 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
AwayTheWInd Master Cheater
Reputation: 0
Joined: 11 Sep 2007 Posts: 450
|
Posted: Sat Feb 21, 2009 9:03 pm Post subject: [VB] Keyboard hook not working |
|
|
my keyboard hook isnt working and the function: KeyboardProc isnt being called.
Option Explicit On
Public Delegate Function KeyboardDelegate(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Class Scanner
Public Const WH_KEYBOARD_LL = 13&
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As KeyboardDelegate, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'if idHook is less than zero, no further processing is required
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, lParam)
Else
If GetAsyncKeyState(16) Then
Button1.Text = "A"
End If
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, lParam)
End If
End Function
Private Sub Scanner_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
UnhookWindowsHookEx(hHook)
End Sub
Private Sub Scanner_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KeyboardProc, System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, AppDomain.GetCurrentThreadId())
End Sub
End Class
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun Feb 22, 2009 12:03 am Post subject: |
|
|
| WH_KEYBOARD, not WH_KEYBOARD_LL
|
|
| Back to top |
|
 |
Zerith Master Cheater
Reputation: 1
Joined: 07 Oct 2007 Posts: 468
|
Posted: Sun Feb 22, 2009 12:04 am Post subject: |
|
|
.NET Doesn't support global hooks, so you better just set a KeyDown even for all the controls:
| Code: | foreach (Control c in Controls)
c.KeyDown += KeyEventHandler(Function); |
If you still want a global hook, make a DLL and load it, then call SetWindowsHookEx with the hInstance of the DLL and the function within the DLL. (don't call SetWindowsHookEx from the DLL because the function mustn't be in the same instance of the calling instance)
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sun Feb 22, 2009 10:28 am Post subject: |
|
|
| Zerith wrote: | .NET Doesn't support global hooks, so you better just set a KeyDown even for all the controls:
| Code: | foreach (Control c in Controls)
c.KeyDown += KeyEventHandler(Function); |
If you still want a global hook, make a DLL and load it, then call SetWindowsHookEx with the hInstance of the DLL and the function within the DLL. (don't call SetWindowsHookEx from the DLL because the function mustn't be in the same instance of the calling instance) |
...
Yeah it does...
Look at my code in the GP+ section.
_________________
|
|
| Back to top |
|
 |
Zerith Master Cheater
Reputation: 1
Joined: 07 Oct 2007 Posts: 468
|
Posted: Sun Feb 22, 2009 10:58 am Post subject: |
|
|
Well, I read somewhere it's not possible, so I googled some and I saw this:
| Quote: | | global hooks are not possible in .NET using the SetWindowsHookEx API, except for MOUSE and KEYBOARD. |
So I guess we both were partially correct.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|