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 


[C Code]What is better?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 511

PostPosted: Sun Oct 17, 2021 6:28 am    Post subject: [C Code]What is better? Reply with quote

What is better when creating and using hotkey?
Code:
GetKeyState()

or
Code:
GetAsyncKeyState() //If exists

?
And game crashing when creating thread in auto assembler script

And one more thing, i can't use hotkey when creating one in c code
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3325

PostPosted: Sun Oct 17, 2021 6:48 am    Post subject: Reply with quote

Async is better because is very fast
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Oct 17, 2021 7:51 pm    Post subject: Reply with quote

Neither is 'better' and have their own purposes.

Csimbi wrote:
Async is better because is very fast


It being 'very fast' is because it is async. It is designed to return immediately with no locking/blocking. However, it has downsides as well because of how it works and can result in inaccurate results when polling for keys based on various conditions.

Some of which can be found on its API page:
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate

GetKeyState has its own ups/downs as well:
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getkeystate

In most cases, GetAsyncKeyState is plenty for hotkeys, but should keep in mind it may fail/not be accurate/not always catch keys depending on what else is running and doing things with the key state buffer of the system.

A more ideal solution would be to hook onto the targets input handling and do things that way for the best accuracy and ability to block presses from reaching the target if you wanted to as well.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1586

PostPosted: Mon Oct 18, 2021 5:57 pm    Post subject: Re: [C Code]What is better? Reply with quote

Frouk wrote:
And one more thing, i can't use hotkey when creating one in c code


if you are making a GUI application and/or using a message loop, and you want to assign multiple hotkeys for several functions you have, then: (choose either one)

- get the state for all keys and parse keys you are interested in using switch case... (GetKeyboardState)
- register system wide hotkey (RegisterHotKey)
- if you are really experienced win32 programmer, then you can go for SetWindowsHookEx (note that you need to inject your dll into target's memory)

this is what I used to do in past when I needed several hotkeys, good luck.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote:
i am a sweetheart.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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