CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2009
    Posts
    20

    [RESOLVED] Windows CE 5.0 - Capture Key Events in VB2005

    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.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Windows CE 5.0 - Capture Key Events in VB2005

    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 ¿

  3. #3
    Join Date
    Jul 2009
    Posts
    20

    Re: Windows CE 5.0 - Capture Key Events in VB2005

    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"...

    or not?

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Windows CE 5.0 - Capture Key Events in VB2005

    Ah good work! ( again )

    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 :
    Code:
    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!

  5. #5
    Join Date
    Jul 2009
    Posts
    20

    Re: Windows CE 5.0 - Capture Key Events in VB2005

    Of Course and Thank You! You'll be informed next hours

  6. #6
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Windows CE 5.0 - Capture Key Events in VB2005

    Might need GetKeyState too.


    Code:
    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.
    Last edited by TT(n); July 23rd, 2009 at 02:10 PM.

  7. #7
    Join Date
    Jul 2009
    Posts
    20

    Re: Windows CE 5.0 - Capture Key Events in VB2005

    Hello,
    thanks TT(n)
    BTW works fine
    But you may use "coredll.dll" instead of "user32" or will not work (Windows CE based GPS)

    Thanks to all!

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Windows CE 5.0 - Capture Key Events in VB2005

    Quote Originally Posted by TT(n) View Post
    Might need GetKeyState too.


    Code:
    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!

    Quote Originally Posted by manny_gt View Post
    Hello,
    thanks TT(n)
    BTW works fine
    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! Well done!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured