Im using the following code to check for a KeyPress.
In this example im checking f1 and when f1 gets pressed down a msgbox popsup:



.DATA

isF1down db 0

.CODE

Invoke GetAsyncKeyState, VK_F1
test eax, 80000000h
setz al

cmp al, 1
je @@store

Invoke MessageBox, hWnd, offset test, offset cap_test, MB_OK+MB_TASKMODAL+MB_ICONWARNING

@@store:
mov [isF1down], al



The Problem is that it doesnt checks if the key was already pressed down and thats why the code gets executed again and again as long as F1 is pressed down.
So how can i change that?

I thought this way it should work:



Invoke GetAsyncKeyState, VK_F1
test eax, 80000000h
setz al

cmp al, 1
je @@store

cmp [isF1down],1
jne @skip

Invoke MessageBox, hWnd, offset test, offset cap_test, MB_OK+MB_TASKMODAL+MB_ICONWARNING

mov [isF1down],0
jmp @skip

@@store:
mov [isF1down], al

@skip:


but it doesnt change anything :(
Posted on 2003-06-25 11:07:12 by Cenox
mov ,0

square brackets shouldn't be there?
Posted on 2003-06-25 22:46:44 by abc123
From the Win32 help file,
Return Values

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. The return value is zero if a window in another thread or process currently has the keyboard focus.

So, if the key is down,


test eax,80000000h ;will be non-zero if down
jz F1_not_down
test eax,1 ;will be non-zero only if 1st instance
jz F1_not_down ;not 1st instance
invoke MessageBox,....
Raymond
Posted on 2003-06-25 23:12:12 by Raymond
mh..
well thanks for the help but i tried it this way and it is still the same...
holding f1 will constantly popup a new msgbox.
Posted on 2003-06-26 11:20:06 by Cenox
Square brackets or no square brackets on a variable result in the same thing. When assembled if you don't use square brackets they are implied and the assembler treats it as if you had dereferenced the varaiable. Otherwise you would be overwriting the address of the variable. Makes you almost agree with Betov that assembler leniency leads to misunderstanding.
Posted on 2003-06-26 14:16:28 by donkey