| View previous topic :: View next topic |
| Author |
Message |
NothingToShow Grandmaster Cheater Supreme
Reputation: 0
Joined: 11 Jul 2007 Posts: 1579
|
Posted: Fri Mar 28, 2008 6:54 am Post subject: |
|
|
| Xenophobe wrote: | | Moller wrote: | | Wiccaan wrote: | They both work in similar ways. But there is a difference.
RegisterHotkey registers the key to the system overriding any other hotkey that is currently using the keypress while GetAsyncKeyState just monitors any key press on your keyboard. (Same with GetKeyState.)
RegisterHotKey is handled via the message pump of a program via the WM_HOTKEY message while GetAsyncKeyState is handled anywhere. (Mostly seen in timers or threads though.)
Also, RegisterHotKey's first param is the handle of the window creating and handling the key. When the key is pressed the system locates the match for the hotkey and sends the WM_HOTKEY message to the message stack of the given window.
RegisterHotKey:
http://msdn2.microsoft.com/en-us/library/ms646309.aspx
| Quote: | When a key is pressed, the system looks for a match against all hot keys. Upon finding a match, the system posts the WM_HOTKEY message to the message queue of the thread that registered the hot key. This message is posted to the beginning of the queue so it is removed by the next iteration of the message loop.
This function cannot associate a hot key with a window created by another thread.
RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key.
If the window identified by the hWnd parameter already registered a hot key with the same identifier as that specified by the id parameter, the new values for the fsModifiers and vk parameters replace the previously specified values for these parameters.
Windows NT4 and Windows 2000/XP: The F12 key is reserved for use by the debugger at all times, so it should not be registered as a hot key. Even when you are not debugging an application, F12 is reserved in case a kernel-mode debugger or a just-in-time debugger is resident. |
GetAsyncKeyState:
http://msdn2.microsoft.com/en-us/library/ms646293.aspx
Simply checks the key state. |
But GetAsyncKeyState still works, right?
For a simple loot bot. |
Yes. |
Okay, thank ya.
But, has RegisterHotkey got any advantages (I think that's how it's spelled...) that GetAsyncKeyState hasn't?. |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 474
Joined: 09 May 2003 Posts: 25953 Location: The netherlands
|
Posted: Fri Mar 28, 2008 7:03 am Post subject: |
|
|
it's instant(well, queued in the message buffer, but that's pretty fast) and not affected by your polling time.
And if you decide to do a constant check for the keypress (e.g poll every 1 ms or less) then it's a cpu hog _________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Mar 28, 2008 8:28 am Post subject: |
|
|
oh really, i've always wondered that, btw, would it have a major effect if you were only checking every 10-20ms?
hehe moller, you should be proud, you got a dark byte worthy discussion _________________
|
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Fri Mar 28, 2008 9:02 am Post subject: |
|
|
Don't use GetAsyncKeyState. If you will put it in a timer it like this
| Code: | if GetAsyncKeyState(VK_F5)<0 then
DoThisProc();//or some code here |
it will repeat the procedure until F5 will be released. |
|
| Back to top |
|
 |
|