View previous topic :: View next topic |
Author |
Message |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Tue Apr 29, 2008 1:56 pm Post subject: Hotkeys? |
|
|
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 |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Tue Apr 29, 2008 1:59 pm Post subject: |
|
|
im not sure, if it works inside a .dll, but did you try RegisterHotKey?
|
|
Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Tue Apr 29, 2008 2:06 pm Post subject: |
|
|
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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue Apr 29, 2008 2:06 pm Post subject: |
|
|
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 |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Wed Apr 30, 2008 1:36 am Post subject: |
|
|
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).
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 |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Wed Apr 30, 2008 6:39 am Post subject: |
|
|
Use RegisterHotkey instead GetAsyncKeyState.
If you don't have a window then SetWindowsHookEx.
By the way, isn't dword = int?
|
|
Back to top |
|
 |
|