[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Keyboard hooks

Posted on 2001-06-24
5
Medium Priority
?
394 Views
Last Modified: 2010-05-02
i set a keyboard hook when my form is loaded and i'm using the lparam to highlight keys on my virtual keyboard my problem is how do i tell a difference between the left and right control or alt keys?
0
Comment
Question by:Ryan9999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:Ark
ID: 6223307
Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
Private Const VK_LSHIFT = &HA0
Private Const VK_RSHIFT = &HA1
Private Const VK_LCONTROL = &HA2
Private Const VK_RCONTROL = &HA3
Private Const VK_LMENU = &HA4
Private Const VK_RMENU = &HA5


Cheers
0
 
LVL 1

Author Comment

by:Ryan9999
ID: 6223570
that doesn't seem to be working
0
 
LVL 28

Expert Comment

by:Ark
ID: 6223879
Hi
another way:

Private Function IsBitSet(iBitString As Long, ByVal lBitNo As Integer) As Boolean
    If lBitNo = 31 Then
        IsBitSet = iBitString < 0
    Else
        IsBitSet = iBitString And (2 ^ lBitNo)
    End If
End Function

Now in your hook callback function:
If IsBitSet(lParam,24) Then
Debug.print "Right shift or control pressed"

Cheers
0
 
LVL 1

Author Comment

by:Ryan9999
ID: 6224157
I must be doing something wrong because that isn't working either here is the code i am using in my module

Option Explicit

Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook As Long, ByVal lpfn As Long,ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long

Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal idHook As Long) As Long

Dim hHook As Long

Public Sub HookKeyboard()
  hHook = SetWindowsHookEx(2, AddressOf Keyboard, App.hInstance, 0)
End Sub

Public Sub UnhookKeyboard()
  If hHook Then
    UnhookWindowsHookEx hHook
    hHook = 0
  End If
End Sub

Private Function Keyboard(ByVal idHook As Long, ByVal lParam As Long, _
  ByVal wParam As Long) As Long

  Form1.Caption = lParam
End Function

0
 
LVL 28

Accepted Solution

by:
Ark earned 200 total points
ID: 6225543
Corrcetions on your code:

1.    hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf Keyboard, App.hInstance, App.ThreadID)

2. Function Keyboard(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If idHook < 0 Then
        Keyboard = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
    Else
       If IsBitSet(lParam,24) Then  
          Form1.Caption = wParam & " (Right)"
       Else
          Form1.Caption = wParam
       End if
    End If
End Function

Cheers
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question