Hi!

I'm having some trouble with GetKeyboardState. This is a part of my code:

invoke GetKeyboardState,addr keybarray
lea edi,
add edi,VK_SHIFT
cmp edi,1
jz ShiftPressed

This isn't working :(

What should I do to check if shift/alt/control is being pressed when using GetKeyboardState?? Does anyone have some sample code?

/Delight
Posted on 2001-10-11 07:51:58 by Delight
Change cmp edi, 1 to test edi, 80h.

The top bit of the byte is whether the key is pressed, the bottom bit is whether it is toggled (it alternates with each key press).

Mirno
Posted on 2001-10-11 08:33:15 by Mirno
Hi Delight

Try changing:

lea edi,

to

lea edi,keybarray


KetilO
Posted on 2001-10-11 08:33:47 by KetilO
First of all, doesn't


lea edi,[keybarray]
and
lea edi,keybarray

do the exact same thing? (Blame masm's stupid I-don't-require- syntax).

Second... delight, you're comparing the *pointer*, not the *value*.
Try
test byte ptr , 80h
instead of
cmp edi, 1

Also, if you want to get to the state of VK_SHIFT immediately, I
believe you can use
lea edi,
or you could do
mov edi, offset keybarray + VK_SHIFT
- whichever suits you best.
Posted on 2001-10-11 12:09:23 by f0dder
Thanks for your help guys! It now works perfect!:alright:


/Delight
Posted on 2001-10-12 04:01:29 by Delight
why not coding simply



test byte ptr [keybarray + VK_SHIFT], 80h


I wonder?

japheth
Posted on 2001-10-12 05:10:51 by japheth
That works too, and I don't have to use an extra register for keybarray! :)

Thanks!

/Delight
Posted on 2001-10-12 05:26:35 by Delight
Hmm....I just found a bug in my app. The GetKeyboardState doesn't work when my window is out of focus. Why is this happening?:confused:


/Delight
Posted on 2001-10-12 05:31:57 by Delight
Delight,
more infos are needed. When do you want to get the keyboard state?

japheth
Posted on 2001-10-12 05:52:22 by japheth
I have a timer that checks the mouse position and if shift/alt/control is being pressed every 500 ms. When I have finished the application, I would like it to start without a dialogbox showing, perhaps in the tray.



/Delight
Posted on 2001-10-12 05:57:54 by Delight
Then possibly consider using a "keyboard hook" with function SetWindowsHookEx().

japheth
Posted on 2001-10-12 07:30:14 by japheth
A keyboard hook? Isn't WM_KEYUP and WM_KEYDOWN the only messages a keyboard hook can handle? Can I use it to check if multiple keys are pressed at the same time?

/Delight
Posted on 2001-10-12 15:02:18 by Delight

A keyboard hook? Isn't WM_KEYUP and WM_KEYDOWN the only messages a keyboard hook can handle? Can I use it to check if multiple keys are pressed at the same time?

/Delight


Hi Delight

Inside the keyboard hook yuu can use GetKeyboardState and post your own message to your window.

KetilO
Posted on 2001-10-12 15:29:34 by KetilO
That's great!

Takk!:alright:


/Delight
Posted on 2001-10-12 15:54:17 by Delight
Hi!

I'm sorry for asking so many qustions, but I am a newbie and I have never used window hooks before...

Is it possible to use GetKeyboardState at any time when using a keyboard hook?? Or only when pressing or releasing a button - can I use it like a proc that I can call whenever I want??

/Delight
Posted on 2001-10-14 08:38:38 by Delight
Hi Delight

From Win32 api I found this:

An application can call this function to retrieve the current status of all the virtual keys. The status changes as a thread removes keyboard messages from its message queue. The status does not change as keyboard messages are posted to the message queue.

I wolud guess each thread has an array in memory so you can use GetKeyboardState whenever you wish. If another thread has keyboard focus you probably will read the wrong values.

KetilO
Posted on 2001-10-14 09:34:07 by KetilO