 |
 |

04-25-2012, 01:35 PM
|
|
Newcomer
|
|
Join Date: Apr 2012
Posts: 4
|
|
[VB.2010] Problem with Key-Hook
|
Hello,
I have a little problem with this source code.
It should spam "bla" when Ctrl + 1 is pressed
Code:
Public Class frmKeytest
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifier As Integer, ByVal vk As Integer) As Integer
Private Declare Sub UnregisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer)
Private Const Key_NONE As Integer = &H0
Private Const WM_HOTKEY As Integer = &H312
Private Const MOD_ALT As Integer = &H1
Private Const MOD_CONTROL As Integer = &H2
Private Const MOD_SHIFT As Integer = &H4
Private Const MOD_WIN As Integer = &H8
Protected Overrides Sub WndProc(ByRef m As Message)
'die messages auswerten
If m.Msg = WM_HOTKEY Then
Select Case m.WParam
Case 1
MessageBox.Show("you pressed Tab")
Case 2
SendKeys.Send("bla")
End Select
End If
MyBase.WndProc(m)
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
UnregisterHotKey(Me.Handle, 1)
UnregisterHotKey(Me.Handle, 2)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RegisterHotKey(Me.Handle, 1, Key_NONE, Keys.Tab)
RegisterHotKey(Me.Handle, 2, MOD_CONTROL, Keys.D1)
End Sub
End Class
|
|

04-25-2012, 04:31 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
|
You're not checking the return value to see if Ctrl-1 is already registered.
MSDN:"RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key."
The code worked fine for me as written.
If I bring up notepad, then press Ctrl-1, "bla" is "typed" into notepad.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Last edited by passel; 04-25-2012 at 04:39 PM.
|

04-26-2012, 02:33 AM
|
|
Newcomer
|
|
Join Date: Apr 2012
Posts: 4
|
|
|
this function works for me too but except for Ctrl + "" hotkeys
it types once "bla" but then sendkeys doesn't work, I have to restart the program
I also tried to use a msgbox instead of sendkeys and this worked fine
but sendkeys still fails..
I think the notepad window is confused because Ctrl is pressed and it only gets
these keys: ctrl+b , ctrl+l , ctrl+a
|
|

04-27-2012, 03:46 AM
|
|
Newcomer
|
|
Join Date: Apr 2012
Posts: 4
|
|
|
/push
still have this problem...
|
|

05-06-2012, 12:39 PM
|
|
Newcomer
|
|
Join Date: Apr 2012
Posts: 4
|
|
/psuh
please help me! 
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|