Results 1 to 5 of 5

Thread: Api to catch kestrokes

  1. #1
    markandeya
    Guest

    Question Api to catch kestrokes

    I need to catch keyboard input so i can then send information codes to programs so a Sanskrit font will be typed. We will programatically catch up to three keys for 1 sanskrit char, one key flagging tht there is a 3 key code coming. How to do through the Api as the catch must be in the backround while a word processing or page formating program is running as the active window. Tnakh you for your help and suggestions. [email protected]

  2. #2
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    If you are running Windows NT/2000/XP you can install a WH_KEYBOARD_LL hook with the SetWindowsHook API call.

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  3. #3
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    uk
    Posts
    327
    Just a query duncan - will that set a global hook? I've read in many places that VB cannot set a global hook, but I'm still curious. I need to be told from a reputable API source... you.

  4. #4
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    Generally speaking you can't implement a system wide hook in Visual basic, because you can't get an activeX dll injected into another application - you need a dll with an exports table for that...
    However some global hooks occur in the operating system layer, specifically WH_KEYBOARD_LL, WH_MOUSE_LL and WH_JOURNALRECORD so they don't suffer from this restriction.

    You can implement a global keyboard hook using the EventVB.dll thus:
    (The syntax is a bit ugly - it's a work in progress...)

    VB Code:
    1. '\\ Form declarations
    2. Private WithEvents apiLink As EventVB.ApiFunctions
    3. Private WithEvents hook As EventVB.EnumHandler
    4.  
    5. '\\ Form load
    6. Private Sub Form_Load()
    7.   Set apiLink = New EventVb.ApiFunctions
    8.   Set hook = apiLink.EventHandlerLink
    9.  
    10.   hook.StartHook WH_KEYBOARD_LL,apiLink.AppModuleHandle, 0
    11.  
    12. End Sub
    13.  
    14. '\\ Form unload
    15. Private Sub Form_Unload(Cancel As Integer)
    16.    hook.StopHook WH_KEYBOARD_LL
    17. End Sub
    18.  
    19. Private Sub hook_HOOKPROCKEYBOARDLL(Action As EventVB.enHookCode, ByVal KeyState As Long, ByVal KeyStrokeInfo As EventVB.ApiKBDLLHOOKSTRUCT, lMsgRet As Long)
    20.  
    21. '\\ Tp prevent a message being passed on to the application,
    22. '\\ set lMsgRet = 1
    23.  
    24. End Sub

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  5. #5
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    because you can't get an activeX dll injected into another application
    Note that I am working on a way around this at the moment but it is proving very troublesome so it's not yet ready ...
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

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