|
-
Aug 29th, 2006, 08:49 AM
#1
[RESOLVED] Keyboard Hooking Question
Ok, here I go again... I built an application that runs on top of a game that I play. I use a keyboard hook to intercept certain keys and pass them through my app. The problem I am haveing is that the commands are getting passed through my application, but is there a way to stop the keys from then being sent to the game as well.
For example I want to intercept Ctrl + T which in my application does something, but in the game, it opens a window. What I want to happen is it to fire the event in my app and then not send that combination to the game and open the window.
I hope I was clear with my question and I thank you in advance for any help
This is the function I am currently using, which works, but the keys still get sent to the game
VB Code:
Public Function IsHooked(ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean
' CTL Keys
Dim key As Integer
Dim mcr As Integer
Dim VK_KEY As Integer
For i As Integer = 0 To setKeys.GetUpperBound(0)
key = setKeys(i).subKey 'The subkey (1=Ctrl,2=Alt,0=none)
mcr = setKeys(i).mcr 'The macro index to be fired
VK_KEY = setKeys(i).key 'The key value
If key = 1 Then 'Subkey is Control
If (Hookstruct.vkCode = VK_KEY) And CBool(GetAsyncKeyState(VK_CONTROL) And &H8000) _
And CBool(Hookstruct.flags And LLKHF_UP) Then
Call mcrFire(mcr)
Return True
ElseIf (Hookstruct.vkCode = VK_KEY) And CBool(GetAsyncKeyState(VK_CONTROL) And &H8000) Then
'Do nothing
End If
ElseIf key = 2 Then 'Subkey is Alt
If (Hookstruct.vkCode = VK_KEY) And CBool(Hookstruct.flags And LLKHF_ALTDOWN) _
And CBool(Hookstruct.flags And LLKHF_UP) Then
Call mcrFire(mcr)
Return True
ElseIf (Hookstruct.vkCode = VK_KEY) And CBool(Hookstruct.flags And LLKHF_ALTDOWN) Then
'Do nothing
End If
Else 'No Subkey
If (Hookstruct.vkCode = VK_KEY) And CBool(Hookstruct.flags And LLKHF_UP) Then
Call mcrFire(mcr)
Return True
ElseIf (Hookstruct.vkCode = VK_KEY) Then
'Do nothing
End If
End If
Next i
'Page up and down for switching macro sets
If (Hookstruct.vkCode = VK_NEXT) And CBool(Hookstruct.flags And LLKHF_UP) Then
MacroSets(1)
Return True
ElseIf (Hookstruct.vkCode = VK_NEXT) Then
Return True
End If
If (Hookstruct.vkCode = VK_PRIOR) And CBool(Hookstruct.flags And LLKHF_UP) Then
MacroSets(-1)
Return True
ElseIf (Hookstruct.vkCode = VK_PRIOR) Then
Return True
End If
Return False
End Function
-
Aug 29th, 2006, 07:50 PM
#2
Re: Keyboard Hooking Question
unfortunately, the low level keyboard hook does not allow you to change messages.
see my signature for a link to hooking external processes
-
Aug 30th, 2006, 07:36 AM
#3
Re: Keyboard Hooking Question
Thanks for the response Moeur. I actually figured out what I was doing wrong and got it working.
I needed to return True on the key down event because it was sending to the game when the key down event was firing and then to my app on the key up event.
Here is my fixed code
VB Code:
Public Function IsHooked(ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean
' CTL Keys
Dim key As Integer
Dim mcr As Integer
Dim VK_KEY As Integer
For i As Integer = 0 To setKeys.GetUpperBound(0)
key = setKeys(i).subKey 'The subkey (1=Ctrl,2=Alt,0=none)
mcr = setKeys(i).mcr 'The macro index to be fired
VK_KEY = setKeys(i).key 'The key value
If key = 1 Then 'Subkey is Control
If (Hookstruct.vkCode = VK_KEY) And CBool(GetAsyncKeyState(VK_CONTROL) And &H8000) _
And CBool(Hookstruct.flags And LLKHF_UP) Then
Call mcrFire(mcr)
Return True
ElseIf (Hookstruct.vkCode = VK_KEY) And CBool(GetAsyncKeyState(VK_CONTROL) And &H8000) Then
Return True '<-------Changed this to Return True
End If
ElseIf key = 2 Then 'Subkey is Alt
If (Hookstruct.vkCode = VK_KEY) And CBool(Hookstruct.flags And LLKHF_ALTDOWN) _
And CBool(Hookstruct.flags And LLKHF_UP) Then
Call mcrFire(mcr)
Return True
ElseIf (Hookstruct.vkCode = VK_KEY) And CBool(Hookstruct.flags And LLKHF_ALTDOWN) Then
Return True '<-------Changed this to Return True
End If
Else 'No Subkey
If (Hookstruct.vkCode = VK_KEY) And CBool(Hookstruct.flags And LLKHF_UP) Then
Call mcrFire(mcr)
Return True
ElseIf (Hookstruct.vkCode = VK_KEY) Then
Return True '<-------Changed this to Return True
End If
End If
Next i
'Page up and down for switching macro sets
If (Hookstruct.vkCode = VK_NEXT) And CBool(Hookstruct.flags And LLKHF_UP) Then
MacroSets(1)
Return True
ElseIf (Hookstruct.vkCode = VK_NEXT) Then
Return True
End If
If (Hookstruct.vkCode = VK_PRIOR) And CBool(Hookstruct.flags And LLKHF_UP) Then
MacroSets(-1)
Return True
ElseIf (Hookstruct.vkCode = VK_PRIOR) Then
Return True
End If
Return False
End Function
Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|