| View previous topic :: View next topic |
| Author |
Message |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Wed Sep 03, 2008 6:10 am Post subject: [C]Using Switch/Case On GetAsyncKeyState ? |
|
|
I want to like use switch/case on GetASyncKeyState (lazy to start if/else).
i was wondering if i would do it like this ?
| Code: | int vKey = VK_F1 | VK_F2 | VK_F3 | VK_F4;
SHORT lol = GetAsyncKeyState(vKey);
swtch(lol)
{
case VK_F1:
case VK_F2:
//and so on..
} |
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Wed Sep 03, 2008 6:22 am Post subject: |
|
|
| SetWindowsHookEx
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Wed Sep 03, 2008 7:40 am Post subject: |
|
|
No.
| Quote: |
Return Value
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. |
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Wed Sep 03, 2008 7:42 am Post subject: |
|
|
| Call GetAsyncKeyState in a loop or just call RegisterHotKey once.
|
|
| Back to top |
|
 |
Kerelmans Advanced Cheater
Reputation: 0
Joined: 29 Oct 2007 Posts: 57
|
Posted: Wed Sep 03, 2008 10:03 am Post subject: |
|
|
| Symbol wrote: | | Call GetAsyncKeyState in a loop or just call RegisterHotKey once. |
Isn't the GetAsyncKeyState value cleared after using the code? so when you loop it it'd just...
I'm not experienced at this... :p
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Sep 04, 2008 5:54 am Post subject: |
|
|
| Symbol wrote: | | Call GetAsyncKeyState in a loop or just call RegisterHotKey once. |
i think i'll do that ;D.
like this yeah ?
| Code: | do
{
SHORT lol = GetAsyncKeyState(ARRAY_OF_HOTKEYS);
if(lol == VK_XX)
else if
//and so on..
}
while(condition); |
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Thu Sep 04, 2008 9:57 am Post subject: |
|
|
| You don't get it. GetAsyncKeyState doesn't return a virtual key code. It returns the state of the key, down or up. It doesn't take an array as a param either.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Sep 04, 2008 10:13 am Post subject: |
|
|
| Zand wrote: | | You don't get it. GetAsyncKeyState doesn't return a virtual key code. It returns the state of the key, down or up. It doesn't take an array as a param either. |
ahh !! then what do i use GetKeyState ?
|
|
| Back to top |
|
 |
Renkokuken GO Moderator
Reputation: 4
Joined: 22 Oct 2006 Posts: 3249
|
Posted: Thu Sep 04, 2008 11:10 am Post subject: |
|
|
| No-one has recommended GetKeyboardState yet..?
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Sep 04, 2008 12:41 pm Post subject: |
|
|
| Rot1 wrote: | | Symbol wrote: | | Call GetAsyncKeyState in a loop or just call RegisterHotKey once. |
i think i'll do that ;D.
like this yeah ?
| Code: | do
{
SHORT lol = GetAsyncKeyState(ARRAY_OF_HOTKEYS);
if(lol == VK_XX)
else if
//and so on..
}
while(condition); |
|
| Code: |
void hotkeyz(void){
while(dicks){
if(GetAsyncKeyState(VK_F10)){
suck();
}
if(GetAsyncKeyState(VK_F11)){
fuck_tabs();
}
}Sleep(100);
} |
Read the MSDN entry.
| Quote: | SHORT GetAsyncKeyState
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. |
Go look at AX in a debugger if you really care.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Sep 04, 2008 12:54 pm Post subject: |
|
|
woah, thanks !! never heard of that API, i'm new to it, thanks Renko!.
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Thu Sep 04, 2008 5:49 pm Post subject: |
|
|
int VirtualKey;
if( GetAsyncKeyState( VirtualKey ) ) {
Switc( VirtualKey ) {
case 0x41:
MessageBox( NULL, "You pushed A", "message", MB_OK );
Break;
//and so on...
}
}
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Fri Sep 05, 2008 5:22 am Post subject: |
|
|
| slippppppppp wrote: | int VirtualKey;
if( GetAsyncKeyState( VirtualKey ) ) {
Switc( VirtualKey ) {
case 0x41:
MessageBox( NULL, "You pushed A", "message", MB_OK );
Break;
//and so on...
}
} |
i will try this also and leave feedback.
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Fri Sep 05, 2008 6:59 am Post subject: |
|
|
| slippppppppp wrote: | int VirtualKey;
if( GetAsyncKeyState( VirtualKey ) ) {
Switc( VirtualKey ) {
case 0x41:
MessageBox( NULL, "You pushed A", "message", MB_OK );
Break;
//and so on...
}
} |
Wrong.
GetAsyncKeyState doesn't get the state of the keyboard, it gets the state of a key, you will get compile error/warning. (Use of uninitialized variable)
|
|
| Back to top |
|
 |
|