Contribute  :  Web Resources  :  Past Polls  :  Site Statistics  :  Downloads  :  Forum  
    BiW ReversingThe challenge is yours    
 Welcome to BiW Reversing
 Wednesday, October 17 2018 @ 02:27 AM CEST
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GetAsyncKeyState API key down or up?

 
Post new topic   Reply to topic    www.reversing.be Forum Index -> Coding Corner
View previous topic :: View next topic  
Author Message
Devoney
Regular
Regular


Joined: 12 Sep 2005
Posts: 110
Location: The Netherlands

PostPosted: Mon Jan 29, 2007 1:05 pm    Post subject: GetAsyncKeyState API key down or up? Reply with quote

Hi all,
I dont understand the description given from API reference about the return value of GetAsyncKeyState

Quote:
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.


How to specify if the currentkey is up or down? what do they mean with the least significan bit and the most significant bit. For example I got a EAX value returned like FFFF8001(h). Wat is the least and most significant bit here.

Thanks in Advance.
Devoney
Back to top
View user's profile Send private message Visit poster's website
detten
Site Admin


Joined: 05 Feb 2005
Posts: 317

PostPosted: Mon Jan 29, 2007 1:23 pm    Post subject: Reply with quote

Quote:
For example I got a EAX value returned like FFFF8001(h). Wat is the least and most significant bit here.


First you need to do the conversion hex -> binary
When you have the binary form the most significant bit is the most left one. (the least significant one the far right one)

Code:

  F      FFF800       1
1111      ...       0001


In your example both most and least significant bit are set.

So in this example the key was pressed . (and it wasn't pressed yet the last time it was checked)

_________________
Ignorance is bliss, knowledge is power
Back to top
View user's profile Send private message Visit poster's website
Devoney
Regular
Regular


Joined: 12 Sep 2005
Posts: 110
Location: The Netherlands

PostPosted: Mon Jan 29, 2007 1:32 pm    Post subject: Reply with quote

Thanks Detten for the quick reply.

So the last time the function was called the key was pressed right? Because the least significant bit is set here? Or am I wrong here?
Quote:
So in this example the key was pressed . (and it wasn't pressed yet the last time it was checked)


Is there an API to convert HEX to BIN ?
And how could I check if these bits are set?

Are these stupid questions? Embarassed
Back to top
View user's profile Send private message Visit poster's website
bpx
Occasional Poster
Occasional Poster


Joined: 22 Jan 2006
Posts: 25
Location: Earth

PostPosted: Mon Jan 29, 2007 2:34 pm    Post subject: Reply with quote

Devoney, no need to convert to BIN. It's more work than you need =)

Use an 'and' to check if bit is set.

in C++ [Checks if enter was pressed]:
if(GetAsyncKeyState(VK_RETURN) & 0x8000) == 0x8000)
{
ButtonWasPressed();
}

Or Asm:

invoke GetAsyncKeyState,VK_RETURN
and eax,08000h
cmp eax,08000h
je _button_pressed

Btw if you haven't found it, you'll prolly need this:
Virtual Key Codes
Back to top
View user's profile Send private message
stingduk
Regular
Regular


Joined: 19 Feb 2005
Posts: 148

PostPosted: Mon Jan 29, 2007 3:22 pm    Post subject: Reply with quote

or you can use test instruction (which is an inbuilt and operation and sets the carry flag)

like
invoke get()
test eax,1
jnz 2badbabe

or you could check out bt instruction

or setcc set of instruction
Back to top
View user's profile Send private message
Devoney
Regular
Regular


Joined: 12 Sep 2005
Posts: 110
Location: The Netherlands

PostPosted: Mon Jan 29, 2007 5:17 pm    Post subject: Reply with quote

The thing I wanted to solve is that when a key is pushed its get logged with WriteFile.

The file then contains the character pushed to write multiplied a couple of times with i.e. the following result:

Quote:
AAAAAAABBBBBBBBBBBBBBBBBBBCCCCCCCCC


I solved this with the following:
Code:

Begin:
PUSH EDI; The virtual keycode
GetAsyncKeyState
CMP EAX, 0;zero means that their is no keypressed or whatsoever
JNE IsKeyPressed;jumps when key is pressed
JMP Begin:
IsKeyPressed:
PUSH EDI; Virtual Keycode
Call GetAsyncKeySate;Check again if the same key is pressed.
CMP EAX, 0;zero means that their is no keypressed or whatsoever
JE WriteToFile;So it jumps when this key is not pressed anymore
JMP IsKeyPressed
WriteToFile:
......


No when the key is pressed the application loops until the key is not pressed anymore and then writing the key to a file. So far I can use this a sollution.
Any better ideas? Razz I think it is a bitt of a odd function.

Thanks for replying!
Devoney
Back to top
View user's profile Send private message Visit poster's website
gabor
Occasional Poster
Occasional Poster


Joined: 13 Jun 2005
Posts: 23

PostPosted: Wed Jan 31, 2007 12:44 am    Post subject: Reply with quote

There is GetKeyState function too:
Quote:
SHORT GetKeyState(

int nVirtKey // virtual-key code
);

_________________
GaBoR {RES}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.reversing.be Forum Index -> Coding Corner All times are GMT + 1 Hour
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 can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
 Copyright © 2018 BiW Reversing
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.11 seconds