View previous topic :: View next topic |
Author |
Message |
andykhoo Newbie cheater Reputation: 0
Joined: 09 Nov 2008 Posts: 17
|
Posted: Wed Mar 10, 2010 7:47 am Post subject: [Delphi] GetAsyncKeyState |
|
|
Hi guys, i'm able to use GetAsyncKeyState to enable a timer and disable...
But that's only for 1 key, let's say I want to use CTRL and F1 to enable a timer, what do i do?
I've tried this but it don't work...
Code: | if odd(GetAsyncKeyState(VK_CONTROL and VK_F1)) |
Enlighten me please?
|
|
Back to top |
|
|
AtheistCrusader Grandmaster Cheater Reputation: 6
Joined: 23 Sep 2006 Posts: 681
|
Posted: Wed Mar 10, 2010 8:12 am Post subject: |
|
|
if odd(GetAsyncKeyState(VK_CONTROL) and GetAsyncKeyState(VK_F1))
|
|
Back to top |
|
|
Slugsnack Grandmaster Cheater Supreme Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Wed Mar 10, 2010 3:24 pm Post subject: |
|
|
i would advise RegisterHotKey() actually
|
|
Back to top |
|
|
iPromise Grandmaster Cheater Reputation: -1
Joined: 27 Jun 2009 Posts: 529 Location: Canada
|
Posted: Sat Mar 13, 2010 7:51 am Post subject: |
|
|
I don't see a difference.
|
|
Back to top |
|
|
Slugsnack Grandmaster Cheater Supreme Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sat Mar 13, 2010 12:33 pm Post subject: |
|
|
iPromise wrote: | I don't see a difference. |
Then you should learn to read documentation. Or possibly get your eyes checked out.
|
|
Back to top |
|
|
iPromise Grandmaster Cheater Reputation: -1
Joined: 27 Jun 2009 Posts: 529 Location: Canada
|
Posted: Sat Mar 13, 2010 8:51 pm Post subject: |
|
|
It would still have the same effect whether you use registerhotkey or getasynckeystate.
|
|
Back to top |
|
|
AtheistCrusader Grandmaster Cheater Reputation: 6
Joined: 23 Sep 2006 Posts: 681
|
Posted: Sat Mar 13, 2010 8:55 pm Post subject: |
|
|
iPromise wrote: | It would still have the same effect whether you use registerhotkey or getasynckeystate. |
...
GetAsyncKeyState > Checking it every x ms.
RegisterHotkey > You receive a message.
RegisterHotkey would be better cause you're not actually checking if the key is pressed every x ms.
|
|
Back to top |
|
|
igoticecream Grandmaster Cheater Supreme Reputation: 0
Joined: 23 Apr 2006 Posts: 1807 Location: 0x00400000
|
Posted: Sun Mar 14, 2010 12:42 am Post subject: |
|
|
iPromise wrote: | I don't see a difference. |
with RegisterHotkey() you define already which key must be hold + desired key... with GetAsyncKeyState() you only get for the desired key
there is alot of diference
_________________
+~ |
|
Back to top |
|
|
iPromise Grandmaster Cheater Reputation: -1
Joined: 27 Jun 2009 Posts: 529 Location: Canada
|
Posted: Sun Mar 14, 2010 10:27 am Post subject: |
|
|
oh, thanks and I understand that but..
whether your waiting for 2 keys to be pressed with getasynckeystate or you register the hotkey, same results, ex:
Code: |
if (GetAsyncKeyState(VK_F11))
{
if (GetAsyncKeyState(VK_F12))
{
...
}
}
|
and if you register the hotkey its exactly like that, but w/e registerhotkeyex is better. I just dont see a difference in the results.
|
|
Back to top |
|
|
Slugsnack Grandmaster Cheater Supreme Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Mar 19, 2010 7:06 am Post subject: |
|
|
iPromise wrote: | oh, thanks and I understand that but..
whether your waiting for 2 keys to be pressed with getasynckeystate or you register the hotkey, same results, ex:
Code: |
if (GetAsyncKeyState(VK_F11))
{
if (GetAsyncKeyState(VK_F12))
{
...
}
}
|
and if you register the hotkey its exactly like that, but w/e registerhotkeyex is better. I just dont see a difference in the results. |
http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx
Learn to read documentation.
Quote: | Return Value
SHORT
If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. However, you should not rely on this last behavior; for more information, see the Remarks. |
Quote: | Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon. |
To put it more obviously, there are two problems indicated there:
- Concurrent calls to GetAsyncKeyState from other processes or possibly even another thread within your same process
- The mechanics of this API means if I pressed the two keys one after another but not at the same time, it would still pass through your loop
You can debate both problems can be fixed by a very dense frequency of calls but it's not really practical, nor 100% foolproof. Especially if he is already using windows then he should try to keep within the windows paradigm although some could argue setting up a timer at X interval and calling GetAsyncKeyState does this.
To summarise: the results are not always the same, something you could have found out by following the advice I gave you earlier in this topic.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Fri Mar 19, 2010 11:25 am Post subject: |
|
|
There is one problem with registerhotkey, but that's more on a game-by-game basis
Some games disable windows hotkey handling, but waitforkeystate still works then (probably directinput related)
So, depending on if the game disabled hotkeys or not, you have to decide if you use registerhotkey or getasynckeystate
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
|