hello!
do you know any good keyboard hook and how can i make it work? :D
i was stuck in one, so any suggestions would b appreciated...
tnx!!!
...and a happy new year...
http://www.vbforums.com/attachment.p...id=32221&stc=1
Printable View
hello!
do you know any good keyboard hook and how can i make it work? :D
i was stuck in one, so any suggestions would b appreciated...
tnx!!!
...and a happy new year...
http://www.vbforums.com/attachment.p...id=32221&stc=1
Can you be more specific?
ALT!!
mmm...yea...
i need a keyboard hook... you know, catching and sending keystrokes with another window active...
BUT, i cant make it work :D
so plz help
bibii
Found this using Google. That article explains how to implement a keyboard hook. For more specific information, perhaps you should tell us what you've done so far and what issues you are having.
i've seen that myself :D ...
BUT, i cant make it work!!!
1.i make the module
2.how i hook it?
:D
tnxxx
That site has full source code. What more can we tell you? You've already been prompted twice for more information.
ok, ok
VB Code:
<MarshalAs(UnmanagedType.FunctionPtr)> _ Private callback As KeyboardHookDelegate Public Sub HookKeyboard() callback = New KeyboardHookDelegate(AddressOf KeyboardCallback) KeyboardHandle = SetWindowsHookEx( _ WH_KEYBOARD_LL, callback, _ Marshal.GetHINSTANCE( _ [Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0) Call CheckHooked() End Sub
i add the module, i use the fucntions to hook it as shown [url="http://www.developer.com/net/vb/article.php/10926_2193301_2"]here[/html], but i got this :
type 'marshalas' is not declared
type 'keyboardhookdelegate' is not declared
type 'keyboardhandle' is not declared
and for all the code...
its just like the module dissapeared...
Now we're getting somewhere. It's much easier to advise when the facts are known.
I pasted the code from that page into a code file and I got no such errors. The only errors I got were related to Option Strict and missing As clauses, which are easily fixed. It sounds to me like you've omitted sections of that code that are required. Here is the code from that page with several annotations relating to the issues you've mentioned.VB Code:
Imports System.Runtime.InteropServices [COLOR=Red]<--- Required to use the MarshalAsAttribute class[/COLOR] Imports System.Reflection Imports System.Drawing Imports System.Threading Module Keyboard Public Declare Function UnhookWindowsHookEx Lib "user32" _ (ByVal hHook As Integer) As Integer Public Declare Function SetWindowsHookEx Lib "user32" _ Alias "SetWindowsHookExA" (ByVal idHook As Integer, _ ByVal lpfn As KeyboardHookDelegate, ByVal hmod As Integer, _ ByVal dwThreadId As Integer) As Integer Private Declare Function GetAsyncKeyState Lib "user32" _ (ByVal vKey As Integer) As Integer Private Declare Function CallNextHookEx Lib "user32" _ (ByVal hHook As Integer, _ ByVal nCode As Integer, _ ByVal wParam As Integer, _ ByVal lParam As KBDLLHOOKSTRUCT) As Integer Public Structure KBDLLHOOKSTRUCT Public vkCode As Integer Public scanCode As Integer Public flags As Integer Public time As Integer Public dwExtraInfo As Integer End Structure ' Low-Level Keyboard Constants Private Const HC_ACTION As Integer = 0 Private Const LLKHF_EXTENDED As Integer = &H1 Private Const LLKHF_INJECTED As Integer = &H10 Private Const LLKHF_ALTDOWN As Integer = &H20 Private Const LLKHF_UP As Integer = &H80 ' Virtual Keys Public Const VK_TAB = &H9 Public Const VK_CONTROL = &H11 Public Const VK_ESCAPE = &H1B Public Const VK_DELETE = &H2E Private Const WH_KEYBOARD_LL As Integer = 13& Public KeyboardHandle As Integer [COLOR=Red]<--- KeyboardHandle declared here.[/COLOR] ' Implement this function to block as many ' key combinations as you'd like Public Function IsHooked( _ ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean Debug.WriteLine("Hookstruct.vkCode: " & Hookstruct.vkCode) Debug.WriteLine(Hookstruct.vkCode = VK_ESCAPE) Debug.WriteLine(Hookstruct.vkCode = VK_TAB) If (Hookstruct.vkCode = VK_ESCAPE) And _ CBool(GetAsyncKeyState(VK_CONTROL) _ And &H8000) Then Call HookedState("Ctrl + Esc blocked") Return True End If If (Hookstruct.vkCode = VK_TAB) And _ CBool(Hookstruct.flags And _ LLKHF_ALTDOWN) Then Call HookedState("Alt + Tab blockd") Return True End If If (Hookstruct.vkCode = VK_ESCAPE) And _ CBool(Hookstruct.flags And _ LLKHF_ALTDOWN) Then Call HookedState("Alt + Escape blocked") Return True End If Return False End Function Private Sub HookedState(ByVal Text As String) Debug.WriteLine(Text) End Sub Public Function KeyboardCallback(ByVal Code As Integer, _ ByVal wParam As Integer, _ ByRef lParam As KBDLLHOOKSTRUCT) As Integer If (Code = HC_ACTION) Then Debug.WriteLine("Calling IsHooked") If (IsHooked(lParam)) Then Return 1 End If End If Return CallNextHookEx(KeyboardHandle, _ Code, wParam, lParam) End Function Public Delegate Function KeyboardHookDelegate( _ ByVal Code As Integer, _ ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) _ As Integer [COLOR=Red]<--- KeyboardHookDelegate declared here.[/COLOR] <MarshalAs(UnmanagedType.FunctionPtr)> _ Private callback As KeyboardHookDelegate Public Sub HookKeyboard() callback = New KeyboardHookDelegate(AddressOf KeyboardCallback) KeyboardHandle = SetWindowsHookEx( _ WH_KEYBOARD_LL, callback, _ Marshal.GetHINSTANCE( _ [Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0) Call CheckHooked() End Sub Public Sub CheckHooked() If (Hooked()) Then Debug.WriteLine("Keyboard hooked") Else Debug.WriteLine("Keyboard hook failed: " & Err.LastDllError) End If End Sub Private Function Hooked() Hooked = KeyboardHandle <> 0 End Function Public Sub UnhookKeyboard() If (Hooked()) Then Call UnhookWindowsHookEx(KeyboardHandle) End If End Sub End Module
ok tnx but now everythings right exept "WH_KEYBOARD_LL" wich is not declared :(
o sh*t... im THAT stupid :D :))
btw what do i enter instead this(all this cllbacks and things
):
SetWindowsHookEx( _
WH_KEYBOARD_LL, callback, _
Marshal.GetHINSTANCE( _
[Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)