Discussion:
Problem with writing a addin for VB IDE - To capture keyboard even
(too old to reply)
San
2007-05-17 11:07:01 UTC
Permalink
Hi,

I am writing an addin for Visual Basic 6.0 IDE to capture the Keyboard events.

However I am not able to figure out how to capture the keyboard events.



A similar application is provided by Microsoft called "TabOrder.vbp" in
Samples.

But the problem with this sample application is that it responds to Keyboard
events when it's window has focus. When the focus is shifted to VB IDE, it
couldn't capture the keyboard events (For Example: Ctrl+P).



One way to do this is to use Window Subclassing (I am suspecious about it,
not sure).



Is there any way to capture the keyboard events in VB IDE?

Please help.



Thanks,

Sandeep
Donald A. Herman
2007-07-02 23:50:59 UTC
Permalink
Your going to have to subclass. And it will be tricky if you are going to
just get the events stimulated in VB.

Below is a snipit I am using for something, To give you an idea of what your
looking into.
ONE method anyway.

Public Function SetHook() As Long
' Dim hInstance As Long

' hInstance = GetWindowLong(Application.hWndAccessApp, GWL_HINSTANCE)

hHook = SetWindowsHookEx(WH_JOURNALRECORD, AddressOf HookProc,
App.hInstance, 0)


SetHook = hHook

End Function

Public Function HookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal
lparam As Long) As Long


If nCode < 0 Then
HookProc = CallNextHookEx(hHook, nCode, wParam, lparam)
Exit Function
End If
Dim i%, j%, k%
CopyMemory EMSG, ByVal lparam, Len(EMSG)


Select Case EMSG.wMsg

Case WM_RBUTTONDOWN


If (hFlags And HFMouseDown) = HFMouseDown Then
If GetAsyncKeyState(vbKeyShift) Then i = 1
If GetAsyncKeyState(vbKeyControl) Then i = 2
If GetAsyncKeyState(vbKeyMenu) Then i = 4
' frmHooked.System_MouseDown 2 ^
((EMSG.wMsg - 513) / 3), i, CSng(EMSG.lParamLow), CSng(EMSG.lParamHigh)
End If
Case WM_RBUTTONUP

' Debug.Print "WM_RBUTTONUP"
' RemoveHook
' If (hFlags And HFMouseUp) = HFMouseUp Then
' If GetAsyncKeyState(vbKeyShift) Then i = 1
' If GetAsyncKeyState(vbKeyControl) Then i = 2
' If GetAsyncKeyState(vbKeyMenu) Then i = 4
' frmHooked.System_MouseUp 2 ^ ((EMSG.wMsg - 514)
/ 3), i, CSng(EMSG.lParamLow), CSng(EMSG.lParamHigh)
Clicked = True
' End If
End Select
Call CallNextHookEx(hHook, nCode, wParam, lparam)
End Function

Public Sub RemoveHook()
UnhookWindowsHookEx hHook

End Sub
--
.
Donald A. Herman
Software - Scheduler Pro, Disk Cataloger, Math Wizard
http://don_herman.tripod.com
Visual Basic Extras, Addins
http://don_herman.tripod.com/vbextras
.
Post by San
Hi,
I am writing an addin for Visual Basic 6.0 IDE to capture the Keyboard events.
However I am not able to figure out how to capture the keyboard events.
A similar application is provided by Microsoft called "TabOrder.vbp" in
Samples.
But the problem with this sample application is that it responds to Keyboard
events when it's window has focus. When the focus is shifted to VB IDE, it
couldn't capture the keyboard events (For Example: Ctrl+P).
One way to do this is to use Window Subclassing (I am suspecious about it,
not sure).
Is there any way to capture the keyboard events in VB IDE?
Please help.
Thanks,
Sandeep
Loading...