 |
|
 |
I tried running the snippet shown with the project - I added a main function to the VS project and I'm having compilation errors.
This is the log: 1>------ Build started: Project: globalhotkeys, Configuration: Debug Win32 ------ 1>Compiling... 1>maintest.cpp 1>c:\users\myuser\desktop\globalhks\maintest.cpp(40) : warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details. 1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\conio.h(145) : see declaration of 'getch' 1>Linking... 1>maintest.obj : error LNK2005: "void __cdecl handA(void *)" (?handA@@YAXPAX@Z) already defined in globalhotkeys.obj 1>maintest.obj : error LNK2005: "void __cdecl handQ(void *)" (?handQ@@YAXPAX@Z) already defined in globalhotkeys.obj 1>maintest.obj : error LNK2005: "void __cdecl hand1(void *)" (?hand1@@YAXPAX@Z) already defined in globalhotkeys.obj 1>maintest.obj : error LNK2005: _main already defined in globalhotkeys.obj 1>.\Debug/globalhotkeys.exe : fatal error LNK1169: one or more multiply defined symbols found 1>Build log was saved at "file://c:\Users\Nitsan\Desktop\globalhks\Debug\BuildLog.htm" 1>globalhotkeys - 5 error(s), 1 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I'm pretty new to C++ and do not understand what exactly should I do with those problems. maintest - the cpp file containing the snippet in the article.
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
1. In int CHotkeyHandler::RemoveHandler(const int index) replace `if (m_listHk.size() < index)` with `if (m_listHk.size() <= index)`, otherwise your `index out of range` check is wrong.
2. I did not find where you actually delete elements from tHotkeyList. Do you? Otherwise it's a potential memory leak, i.e. if we add/delete hotkeys, memory does not get deallocated.
3. Please remove `using std::vector;` from the header file, it may screw the users code after #include "HotkeyHandler.h", if user has a non STD implementation of vector. using ANYTHING; in the global scope is always bad.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
1. fixed 2. Currently, I don't delete but I recycle. every deleted item is marked as deleted and when you insert a new element it will take its place. 3. fixed
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
Hi,
I cannot think of something optimal at the moment, but here is what comes to mind at first:
--- create a thread that will keep calling GetKeyState() and checking whether the desired key combination is made. If so then signal to your main thread to take action. ---
hope that helps, lallous
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I've been using global hotkeys (with MFC) for a while.
Recently, I found out that what I was doing with the hotkeys can be done using a keyboard hook as well. I don't know much about hooks. So, I was wonder if anybody could help me by listing the pros and cons of the two methods as opposed to each other
Much appreciated.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
Keyboard hooks are useful and much powerful, however global hotkeys can serve your simple needs.
Hook: .mostly need a additional dll where the hook code will reside .mostly need to get itself attached to every running process thus adding possibility to slow down the system .are powerful and can be triggered even from inside games .can be used as filters (you can decide whether to passdown a key or not)
Global hotkeys: .sometimes they are not triggered from inside games .they are light and for one purpose (get triggered on hotkey)
Hope that helps, Elias
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Then how do we do hooks?
I tried this code snippet, it compiled and everything but failed with error code 4 (could not register key??) I removed all but '1', and then it would compile but when I press 1 anywhere nothing happens, pressing 1 within the console program ends it.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
article: hk.InsertHandler(MOD_CONTROL | MOD_ALT, 'Q', handQ, id); hk.InsertHandler(MOD_CONTROL | MOD_ALT, 'A', handA, id); hk.InsertHandler(MOD_CONTROL | MOD_ALT, '1', hand1, id);
1) The reason that you are getting 'could not register key' is probably because those hotkeys are already registered for/by other applications.
2) Don't press '1', press CONTROL+ALT+1 ...check the article again and the quoted code in this reply to see how the hotkeys were registered. -- Elias
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
It's a good idea to solut;Pion the HotKey problem;but why do u use the fuction "EndRaceProtection()"&"BeginRaceProtection()"?Is there synchronous problem?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello,
Yes there might be synchronization problem especially when two processes using this class try to manage the same hotkeys.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello,Lallous sorry i'm not really understand When two Processes are using the class(try to manage the same hotkeys),the Mutex is want to protect what? When the Star()is called ,the Hotkey has been registed ,Has CreateThread() in other process synchronization problem?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello,
Do not worry about synch. problems, they are already handled.
I saw when two programs are trying to register/unregister same hotkeys (using my class) they might be problems, but w/ my code I protect such cases.
A problem might occur just after a process registers an atom for the hotkey and is going to call RegisterHotKey() while another process tries to unregisterHotkey() and delete the atom.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Not exactly what I expect from a tutorial.
A step-by-step introduction what are "global hotkeys", various possibilities to implement them with their advantages and downsides, and a detailed explanation of the implementation you chose.
A sample project with a code snippet showing how to use it is barely enough for "normal" article, less so for a tutorial.
Please consider reworking the article, or removing it from the tutorial section
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello Peter,
In codeproject, I saw lots of articles just like this one that demonstrates how to use a class and no more.
I do explain things very well inside the source code itself. However I see that you are right, maybe I should expand this article.
Regards, Lallous
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Lallous, please consider my previous post "constructive criticism", not as blame 
Yes, there are many articles like that - and the 'oldtimers' on this site agree it's just too many. Codeproject was, and is, a high quality source for developers, and that's why many people stay here. I, as most others, welcome the open structure of CP where everybody can post his articles. However, with the recent rapid increase of members, the average "care" an article gets has decayed.
I must admit I didn't even DL your source, because the article I saw looked more like a "quick job", and I expect(ed) the code to be the same. It would be a pity if this happens to your article all the time.
Good luck, and keep the articles coming  Peter
btw. Marc has written up some points about how to write a good article[^]. I don't agree 100% with it, and would have certain points to add, but it's a good starting point, and I browse it anytime I plan up a new article.
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello Peter,
>please consider my previous post "constructive criticism", not as blame Yes sure...This is the second time you give me constructive comments.
I'll read Marc's article and try to make mine a much detailed article.
Thanks again, Lallous
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This looks very useful for us; however, the example project doesn't seem to work on my box (WinXP Home). I set a breakpoint within the message loop to fire if the WM_HOTKEY message was passed. The code never hit the breakpoint.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |