| View previous topic :: View next topic |
| Author |
Message |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Jun 06, 2008 10:40 pm Post subject: how to find value of key pressed in delphi |
|
|
im trying to find the virtual key value of a key pressed in delphi so i can set it to a variable, i can use GetASyncKeyState, but that requires a load of ifs, anyway to just set it straight to a variable
_________________
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jun 07, 2008 12:21 am Post subject: |
|
|
CreateWindowsHookEx() using the LL_HOOK message, I believe it is. You should set up a low level keyboard hook with that API.
I'm sure there are plenty examples on the web.
_________________
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Sat Jun 07, 2008 12:30 am Post subject: |
|
|
thanks, i will have a look around
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Jun 07, 2008 9:16 am Post subject: |
|
|
He's not trying to create a hotkey, or at least I don't think. Because he said he wants to store it in a variable.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sat Jun 07, 2008 9:33 am Post subject: |
|
|
I'm guessing he wants custom input keys for his MS bot.
Have the user press a button to set the key. When the button is pressed, call a new function:
| Code: |
do{GetMessage( &msg, NULL, 0, 0 )}
while(msg.message != WM_KEYDOWN)
return msg.wParam; |
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Jun 07, 2008 9:50 am Post subject: |
|
|
| Code: |
DWORD vk;
while(GetMessage(&msg, NULL, 0, 0) > 0) {
if(msg.message != WM_KEYDOWN) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
//get vk here not sure how though
}
return msg.wParam;
|
I'm not quite sure how to get the vk. Could you do like...
| Code: |
else {
vk = (DWORD)msg.wParam;
}
|
Because the vk would be in the wParam right? Like if they hit the 'z' key, then the wParam would be 0x5A.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sat Jun 07, 2008 9:56 am Post subject: |
|
|
wParam is a DWORD, 4 bytes
The WM_KEYDOWN is broken up liek: http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx
If you just want to get the 1 byte scancode which is 1 byte into the wParam, you could try something like:
| Code: | | BYTE vk = (BYTE)*(((void*)(msg.wParam))+1) |
EDIT: disregard the above was thinking about lparam
wParam is a DWORD, 4 bytes, but all it contains is the scancode.
| Code: | | BYTE vk = msg.wParam; |
should work.
_________________
Last edited by HalfPrime on Sat Jun 07, 2008 10:04 am; edited 2 times in total |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Jun 07, 2008 10:02 am Post subject: |
|
|
| Code: |
BYTE vk;
while(GetMessage(&msg, NULL, 0, 0) > 0) {
if(msg.message != WM_KEYDOWN) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
vk = msg.wParam;
}
}
return msg.wParam;
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
Last edited by oib111 on Sat Jun 07, 2008 10:29 am; edited 1 time in total |
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sat Jun 07, 2008 10:10 am Post subject: |
|
|
That'll give you the scankey code instead of the virtual key code.
_________________
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Sat Jun 07, 2008 10:34 am Post subject: |
|
|
how would you get the vk then?
_________________
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sat Jun 07, 2008 10:35 am Post subject: |
|
|
| HalfPrime wrote: | | Code: | | BYTE vk = msg.wParam; |
should work. |
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Jun 07, 2008 10:36 am Post subject: |
|
|
| oib111 wrote: | | Code: |
BYTE vk;
while(GetMessage(&msg, NULL, 0, 0) > 0) {
if(msg.message != WM_KEYDOWN) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
vk = msg.wParam;
}
}
return msg.wParam;
|
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Sat Jun 07, 2008 12:18 pm Post subject: |
|
|
Some more insight on this:
http://msdn.microsoft.com/en-us/library/ms646268(VS.85).aspx
You can make your own version of GetKeyboardState as well handling WM_KEYDOWN and WM_KEYUP with your own array. Which you would commonly see done in game programming to handle key events.
_________________
- Retired. |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25974 Location: The netherlands
|
Posted: Sat Jun 07, 2008 12:22 pm Post subject: Re: how to find value of key pressed in delphi |
|
|
| Snootae wrote: | | im trying to find the virtual key value of a key pressed in delphi so i can set it to a variable, i can use GetASyncKeyState, but that requires a load of ifs, anyway to just set it straight to a variable |
Try the onkeydown event on the focused object. key will contain the virtual key value
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sat Jun 07, 2008 1:35 pm Post subject: |
|
|
| HalfPrime wrote: | wParam is a DWORD, 4 bytes
The WM_KEYDOWN is broken up liek: http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx
If you just want to get the 1 byte scancode which is 1 byte into the wParam, you could try something like:
| Code: | | BYTE vk = (BYTE)*(((void*)(msg.wParam))+1) |
EDIT: disregard the above was thinking about lparam
wParam is a DWORD, 4 bytes, but all it contains is the scancode.
| Code: | | BYTE vk = msg.wParam; |
should work. |
wParam = WORD (2 Bytes) Parameter, lParam = LONG (LongInt) Parameter
Check this out - http://rot1blg.wordpress.com/2008/05/16/table-of-contents/
|
|
| Back to top |
|
 |
|