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 


Hotkeys?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Tue Apr 29, 2008 1:56 pm    Post subject: Hotkeys? Reply with quote

Hi,
I wrote a dll that's injected into a game, and I want to be able to change some options on and off, using hotkeys.
What I've done untill now is:
create a loop, which calls GetAsyncKeyState every xx milliseconds, but sometimes it didn't work for some reason. I've read about CreateWindowEx with HOTKEY_CLASS, but I don't know how that works.
Are there any other methods? What's the best method for creating hotkeys in an injected dll?
Thanks in advance.
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Tue Apr 29, 2008 1:59 pm    Post subject: Reply with quote

im not sure, if it works inside a .dll, but did you try RegisterHotKey?
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Tue Apr 29, 2008 2:06 pm    Post subject: Reply with quote

What you're probably doing is toggling the command twice.
You press the button
The loop sees that the button is pressed
toggle command
loop restarts
You're still holding the button, so it's still pressed
toggle comand again
you take your finger off the button

use
Code:
if(GetAsyncKeyState(whatever)&0x8000)

the 0x8000 will make it check the high bit which is whether or not it was pressed since the last time GetAsyncKeyState was called. Otherwise, it just checks if it's currently down.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Apr 29, 2008 2:06 pm    Post subject: Reply with quote

If you have created a form from the dll then use RegisterHotKey and filter with WM_HOTKEY in the Window Procedure.

If you didn't then you have to use GetAsyncKeyState or Create a Keyboard hook.

_________________
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Wed Apr 30, 2008 1:36 am    Post subject: Reply with quote

HalfPrime wrote:
What you're probably doing is toggling the command twice.
You press the button
The loop sees that the button is pressed
toggle command
loop restarts
You're still holding the button, so it's still pressed
toggle comand again
you take your finger off the button

I thought that too, but that's not the problem, I've even put in a Sleep(500).
A part of my dll is saving the current location of you're character, and teleporting to the saved location. (e.g. CTRL + NUMPAD 5 = Save, NUMPAD 5 = Teleport) The code below worked fine first, but then I added another part checking a key to turn this teleport stuff on and off, but then it didn't work anymore. It does notice when I press a numpad key, but it never 'sees' the control key anymore.
Code:

mov edi, VK_NUMPAD1
.repeat
   invoke GetAsyncKeyState, edi
   and eax, 80000000h
   .if eax != 0
      invoke GetAsyncKeyState, VK_CONTROL    ;This one always returns 0 for some reason
      and eax, 80000000h
      .if eax != 0
         ;Save current location
      .else
         ;Teleport to saved location
      .endif
   .endif
   inc edi
.until edi > VK_NUMPAD9


Quote:
use
Code:
if(GetAsyncKeyState(whatever)&0x8000)

the 0x8000 will make it check the high bit which is whether or not it was pressed since the last time GetAsyncKeyState was called. Otherwise, it just checks if it's currently down.
Yes I already had that...
EDIT: Omg, I didn't notice GetAsyncKeyState returns a word (short) instead of a dword (long). Shocked


I don't know if i'm gonna make a window yet. I might even make an in-game window (I wanna learn dx overlays)
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Wed Apr 30, 2008 6:39 am    Post subject: Reply with quote

Use RegisterHotkey instead GetAsyncKeyState.
If you don't have a window then SetWindowsHookEx.

By the way, isn't dword = int? Surprised
Back to top
View user's profile Send private message
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