Click to See Complete Forum and Search --> : [RESOLVED] Windows CE 5.0 - Capture Key Events in VB2005
manny_gt
July 23rd, 2009, 03:30 AM
Hello :)
I have to handle a particular kind of KeyDown event.
I have made a new virtualdesktop for my GPS Windows CE based thats launch an external program (like TomTom). I have to handle and capture event when key wheels are pressed (volume control).
I know only like as "Private Sub Form1_KeyDown()" but this function works only when Form1 is focused... How can I continue to get and traps event when my TomTom is still running and focused?
Thank You.
HanneSThEGreaT
July 23rd, 2009, 07:25 AM
Try the GetAsyncKeyState API. It will allow you to get the particular key that was pressed down in the external app.
Do you know about APIs ¿
manny_gt
July 23rd, 2009, 07:37 AM
Yes. I've found this:
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Of course, have I to change "user32" with "coredll" ?
Thanks..
If it's correct I just need to put it in a module.vb. I've also found these function
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
These are related functions for an "API-timer"
I think "these are the functions that I need"...
:D or not?
HanneSThEGreaT
July 23rd, 2009, 07:51 AM
Ah good work! ( again :p )
No, you mustn't change user32.dll to Corel.dll, as GetAsyncState resides inside user32.dll. So, when these APIs are being used, you are actually using the methods inside user32.dll - interesting huh ¿
Keep in mind that, those declarations are still for VB 6, and not really for VB.NET. They would look like this in VB.NET :
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As Short
Public Declare Function SetTimer Lib "user32.dll" (ByVal hWnd As Int32, ByVal nIDEvent As Int32, ByVal uElapse As Int32, ByVal lpTimerFunc As Int32) As Int32
Public Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Int32, ByVal nIDEvent As Int32) As Int32
You'll notice the changes in the data types being used :)
Let us know if you come right, and good luck! :thumb:
manny_gt
July 23rd, 2009, 07:52 AM
Of Course and Thank You! You'll be informed next hours :)
TT(n)
July 23rd, 2009, 01:41 PM
Might need GetKeyState too.
Private Declare Function apiGetKeyState Lib "user32" Alias "GetKeyState" (ByVal vKey As Int32) As Int32
If the function succeeds, the return value specifies the status of the given virtual key. If the high-order bit is 1, the key is down; otherwise, it is up. If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key’s indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.
I usually end up using GetAsyncKeyState for extended keys, like shift, alt, ctrl, because both will work a little differently.
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.
EDIT:
GetKeyState
Return values for down, are -127, or -128.
Return values for up, are 0 or 1.
GetAsyncKeyState
Return value for down is -32767
Return value for up is 0 or 1. (depends, and can be a little inconsistent.)
I thought I remembered a couple variations of these returns, but I couldn't reproduce them.
manny_gt
July 23rd, 2009, 03:49 PM
Hello,
thanks TT(n)
BTW works fine :D
But you may use "coredll.dll" instead of "user32" or will not work (Windows CE based GPS)
Thanks to all! :)
HanneSThEGreaT
July 24th, 2009, 01:19 AM
Might need GetKeyState too.
Private Declare Function apiGetKeyState Lib "user32" Alias "GetKeyState" (ByVal vKey As Int32) As Int32
I usually end up using GetAsyncKeyState for extended keys, like shift, alt, ctrl, because both will work a little differently.
EDIT:
GetKeyState
Return values for down, are -127, or -128.
Return values for up, are 0 or 1.
GetAsyncKeyState
Return value for down is -32767
Return value for up is 0 or 1. (depends, and can be a little inconsistent.)
I thought I remembered a couple variations of these returns, but I couldn't reproduce them.
Great! I Forgot that one! Age... LOL!
Hello,
thanks TT(n)
BTW works fine :D
But you may use "coredll.dll" instead of "user32" or will not work (Windows CE based GPS)
Thanks to all! :)
Great that you came right! :thumb: Well done! :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.