Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Delphi] GetAsyncKeyState

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
andykhoo
Newbie cheater
Reputation: 0

Joined: 09 Nov 2008
Posts: 17

PostPosted: Wed Mar 10, 2010 7:47 am    Post subject: [Delphi] GetAsyncKeyState Reply with quote

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
View user's profile Send private message MSN Messenger
AtheistCrusader
Grandmaster Cheater
Reputation: 6

Joined: 23 Sep 2006
Posts: 681

PostPosted: Wed Mar 10, 2010 8:12 am    Post subject: Reply with quote

if odd(GetAsyncKeyState(VK_CONTROL) and GetAsyncKeyState(VK_F1))
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Mar 10, 2010 3:24 pm    Post subject: This post has 1 review(s) Reply with quote

i would advise RegisterHotKey() actually
Back to top
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Sat Mar 13, 2010 7:51 am    Post subject: Reply with quote

I don't see a difference.
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sat Mar 13, 2010 12:33 pm    Post subject: This post has 1 review(s) Reply with quote

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
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Sat Mar 13, 2010 8:51 pm    Post subject: Reply with quote

It would still have the same effect whether you use registerhotkey or getasynckeystate.
Back to top
View user's profile Send private message MSN Messenger
AtheistCrusader
Grandmaster Cheater
Reputation: 6

Joined: 23 Sep 2006
Posts: 681

PostPosted: Sat Mar 13, 2010 8:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
igoticecream
Grandmaster Cheater Supreme
Reputation: 0

Joined: 23 Apr 2006
Posts: 1807
Location: 0x00400000

PostPosted: Sun Mar 14, 2010 12:42 am    Post subject: Reply with quote

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
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Sun Mar 14, 2010 10:27 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Mar 19, 2010 7:06 am    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Fri Mar 19, 2010 11:25 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites