This is one of my projects I have been working on the past weeks. Features:
- User can set the hotkey to anything they want!
- Reset hotkey
- More advanced hotkey system than the other one's.
People who made this possible:
Aoen 70%
Hejsan 30%
What you need:
2 Buttons
1 textbox
1 Form
Then past this source, just remember give credits if you use this in your programs/hacks.
[php]Imports System.Runtime.InteropServices
Public Class Form1
Dim T As New KeysConverter
Friend Shortcuss(7) As Shortcut, System As Boolean
Private Sub TextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
Select Case e.KeyCode
Case Keys.ShiftKey, Keys.ControlKey, Keys.Menu
Return
Case Else
sender.Text = *****nvertToString(e.KeyCode)
End Select
End Sub
Private Sub Settings_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
If Visible Then
For Each S In Shortcuss
If S IsNot Nothing Then S.Unregister()
Next
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.BackColor = Color.White
TextBox1.ReadOnly = True
TextBox1.TextAlign = HorizontalAlignment.Center
For Each C In Controls
If TypeOf C Is TextBox Then AddHandler DirectCast(C, TextBox).KeyDown, AddressOf TextBox_KeyDown
Next
End Sub
Sub Shortcuss_Pressed(ByVal sender As Shortcut)
MsgBox("Hotkey Pressed!")
'Do something..
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Hotkey set to: " & TextBox1.Text, MsgBoxStyle******rmation)
For Each C In Controls
If TypeOf C Is TextBox Then
If C.Text <> "" Then
Dim ID = Val(C.Name.Substring(7)) - 1, M(3) As Shortcut.Modifier
For I = 0 To 2
M(I) = 0
Next
If Shortcuss(ID) IsNot Nothing Then Shortcuss(ID).Unregister()
Dim X As New Shortcut
X.Register(M(0) Or M(1) Or M(2), *****nvertFromString(C.Text))
AddHandler X.Pressed, AddressOf Shortcuss_Pressed
Shortcuss(ID) = X
End If
End If
Next
End Sub
Class Shortcut : Inherits NativeWindow
Private Declare Auto Function RegisterHotKey Lib "user32" (ByVal handle As IntPtr, ByVal id As Integer, ByVal modifier As Integer, ByVal key As Integer) As Integer
Private Declare Auto Function UnregisterHotKey Lib "user32" (ByVal handle As IntPtr, ByVal id As Integer) As Integer
Enum Modifier : None = 0 : Alt = 1 : Ctrl = 2 : Shift = 4 : End Enum
Event Pressed(ByVal sender As Shortcut) : Dim ID As Integer
Sub New()
CreateHandle(New CreateParams) : ID = GetHashCode()
End Sub
Sub Register(ByVal modifier As Modifier, ByVal key As Keys)
RegisterHotKey(Handle, ID, modifier, key)
End Sub
Sub Unregister()
UnregisterHotKey(Handle, ID)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = 786 Then RaiseEvent Pressed(Me)
MyBase.WndProc(m)
End Sub
End Class
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("Hotkeys has been reset.", MsgBoxStyle******rmation)
For Each C In Controls
If TypeOf C Is TextBox Then
If C.Text <> "" Then
Dim ID = Val(C.Name.Substring(7)) - 1, M(3) As Shortcut.Modifier
For I = 0 To 2
If Combo = "F1" Then
hotkey2 = GetAsyncKeyState(Keys.F1)
ElseIf Combo = "F2" Then
hotkey2 = GetAsyncKeyState(Keys.F2)
ElseIf Combo = "F3" Then
hotkey2 = GetAsyncKeyState(Keys.F3)
ElseIf Combo = "F4" Then
hotkey2 = GetAsyncKeyState(Keys.F4)
ElseIf Combo = "F5" Then
hotkey2 = GetAsyncKeyState(Keys.F5)
ElseIf Combo = "F6" Then
hotkey2 = GetAsyncKeyState(Keys.F6)
ElseIf Combo = "F7" Then
hotkey2 = GetAsyncKeyState(Keys.F7)
ElseIf Combo = "F8" Then
hotkey2 = GetAsyncKeyState(Keys.F8)
ElseIf Combo = "F9" Then
hotkey2 = GetAsyncKeyState(Keys.F9)
ElseIf Combo = "F10" Then
hotkey2 = GetAsyncKeyState(Keys.F10)
ElseIf Combo = "F12" Then
hotkey2 = GetAsyncKeyState(Keys.F11)
ElseIf Combo = "F12" Then
hotkey2 = GetAsyncKeyState(Keys.F12)
ElseIf Combo = "A" Then
hotkey2 = GetAsyncKeyState(Keys.A)
ElseIf Combo = "B" Then
hotkey2 = GetAsyncKeyState(Keys.B)
ElseIf Combo = "C" Then
hotkey2 = GetAsyncKeyState(Keys.C)
ElseIf Combo = "D" Then
hotkey2 = GetAsyncKeyState(Keys.D)
ElseIf Combo = "E" Then
hotkey2 = GetAsyncKeyState(Keys.E)
ElseIf Combo = "F" Then
hotkey2 = GetAsyncKeyState(Keys.F)
ElseIf Combo = "G" Then
hotkey2 = GetAsyncKeyState(Keys.G)
ElseIf Combo = "H" Then
hotkey2 = GetAsyncKeyState(Keys.H)
ElseIf Combo = "I" Then
hotkey2 = GetAsyncKeyState(Keys.I)
ElseIf Combo = "J" Then
hotkey2 = GetAsyncKeyState(Keys.J)
ElseIf Combo = "K" Then
hotkey2 = GetAsyncKeyState(Keys.K)
ElseIf Combo = "L" Then
hotkey2 = GetAsyncKeyState(Keys.L)
ElseIf Combo = "M" Then
hotkey2 = GetAsyncKeyState(Keys.M)
ElseIf Combo = "N" Then
hotkey2 = GetAsyncKeyState(Keys.N)
ElseIf Combo = "O" Then
hotkey2 = GetAsyncKeyState(Keys.O)
ElseIf Combo = "P" Then
hotkey2 = GetAsyncKeyState(Keys.P)
ElseIf Combo = "Q" Then
hotkey2 = GetAsyncKeyState(Keys.Q)
ElseIf Combo = "R" Then
hotkey2 = GetAsyncKeyState(Keys.R)
ElseIf Combo = "S" Then
hotkey2 = GetAsyncKeyState(Keys.S)
ElseIf Combo = "T" Then
hotkey2 = GetAsyncKeyState(Keys.T)
ElseIf Combo = "U" Then
hotkey2 = GetAsyncKeyState(Keys.U)
ElseIf Combo = "V" Then
hotkey2 = GetAsyncKeyState(Keys.V)
ElseIf Combo = "W" Then
hotkey2 = GetAsyncKeyState(Keys.W)
ElseIf Combo = "X" Then
hotkey2 = GetAsyncKeyState(Keys.X)
ElseIf Combo = "Y" Then
hotkey2 = GetAsyncKeyState(Keys.Y)
ElseIf Combo = "Z" Then
hotkey2 = GetAsyncKeyState(Keys.Z)
Else
hotkey2 = GetAsyncKeyState(Keys.F1)
End If
And so on xD
Originally Posted by Blubb1337
I was going to do such -.-
But way more chooby =/
Like...
Code:
If Combo = "F1" Then
hotkey2 = GetAsyncKeyState(Keys.F1)
ElseIf Combo = "F2" Then
hotkey2 = GetAsyncKeyState(Keys.F2)
ElseIf Combo = "F3" Then
hotkey2 = GetAsyncKeyState(Keys.F3)
ElseIf Combo = "F4" Then
hotkey2 = GetAsyncKeyState(Keys.F4)
ElseIf Combo = "F5" Then
hotkey2 = GetAsyncKeyState(Keys.F5)
ElseIf Combo = "F6" Then
hotkey2 = GetAsyncKeyState(Keys.F6)
ElseIf Combo = "F7" Then
hotkey2 = GetAsyncKeyState(Keys.F7)
ElseIf Combo = "F8" Then
hotkey2 = GetAsyncKeyState(Keys.F8)
ElseIf Combo = "F9" Then
hotkey2 = GetAsyncKeyState(Keys.F9)
ElseIf Combo = "F10" Then
hotkey2 = GetAsyncKeyState(Keys.F10)
ElseIf Combo = "F12" Then
hotkey2 = GetAsyncKeyState(Keys.F11)
ElseIf Combo = "F12" Then
hotkey2 = GetAsyncKeyState(Keys.F12)
ElseIf Combo = "A" Then
hotkey2 = GetAsyncKeyState(Keys.A)
ElseIf Combo = "B" Then
hotkey2 = GetAsyncKeyState(Keys.B)
ElseIf Combo = "C" Then
hotkey2 = GetAsyncKeyState(Keys.C)
ElseIf Combo = "D" Then
hotkey2 = GetAsyncKeyState(Keys.D)
ElseIf Combo = "E" Then
hotkey2 = GetAsyncKeyState(Keys.E)
ElseIf Combo = "F" Then
hotkey2 = GetAsyncKeyState(Keys.F)
ElseIf Combo = "G" Then
hotkey2 = GetAsyncKeyState(Keys.G)
ElseIf Combo = "H" Then
hotkey2 = GetAsyncKeyState(Keys.H)
ElseIf Combo = "I" Then
hotkey2 = GetAsyncKeyState(Keys.I)
ElseIf Combo = "J" Then
hotkey2 = GetAsyncKeyState(Keys.J)
ElseIf Combo = "K" Then
hotkey2 = GetAsyncKeyState(Keys.K)
ElseIf Combo = "L" Then
hotkey2 = GetAsyncKeyState(Keys.L)
ElseIf Combo = "M" Then
hotkey2 = GetAsyncKeyState(Keys.M)
ElseIf Combo = "N" Then
hotkey2 = GetAsyncKeyState(Keys.N)
ElseIf Combo = "O" Then
hotkey2 = GetAsyncKeyState(Keys.O)
ElseIf Combo = "P" Then
hotkey2 = GetAsyncKeyState(Keys.P)
ElseIf Combo = "Q" Then
hotkey2 = GetAsyncKeyState(Keys.Q)
ElseIf Combo = "R" Then
hotkey2 = GetAsyncKeyState(Keys.R)
ElseIf Combo = "S" Then
hotkey2 = GetAsyncKeyState(Keys.S)
ElseIf Combo = "T" Then
hotkey2 = GetAsyncKeyState(Keys.T)
ElseIf Combo = "U" Then
hotkey2 = GetAsyncKeyState(Keys.U)
ElseIf Combo = "V" Then
hotkey2 = GetAsyncKeyState(Keys.V)
ElseIf Combo = "W" Then
hotkey2 = GetAsyncKeyState(Keys.W)
ElseIf Combo = "X" Then
hotkey2 = GetAsyncKeyState(Keys.X)
ElseIf Combo = "Y" Then
hotkey2 = GetAsyncKeyState(Keys.Y)
ElseIf Combo = "Z" Then
hotkey2 = GetAsyncKeyState(Keys.Z)
Else
hotkey2 = GetAsyncKeyState(Keys.F1)
End If
And so on xD
Naw, thats much harder to get it work.
In "my" program you click on the textbox and press on the button 1 time. Then it
it appears on the textbox: numpad1
You will get it when next approved
I do know, duh.
You ruined my whole plan!!!!
/lose
hotkey 4 what??? i don't understand....
Easier way would be using a low level keyboard hook using SetWindowsHookEx, I think NextGen1 released something like this in his VB.NET SDK, I didn't look over it completely yet.
Originally Posted by hejsan
This is one of my projects I have been working on the past weeks. Features:
- User can set the hotkey to anything they want!
- Reset hotkey
- More advanced hotkey system than the other one's.
People who made this possible:
Aoen 70%
Hejsan 30%
What you need:
2 Buttons
1 textbox
1 Form
Then past this source, just remember give credits if you use this in your programs/hacks.
[php]Imports System.Runtime.InteropServices
Public Class Form1
Dim T As New KeysConverter
Friend Shortcuss(7) As Shortcut, System As Boolean
Private Sub TextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
Select Case e.KeyCode
Case Keys.ShiftKey, Keys.ControlKey, Keys.Menu
Return
Case Else
sender.Text = *****nvertToString(e.KeyCode)
End Select
End Sub
Private Sub Settings_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
If Visible Then
For Each S In Shortcuss
If S IsNot Nothing Then S.Unregister()
Next
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.BackColor = Color.White
TextBox1.ReadOnly = True
TextBox1.TextAlign = HorizontalAlignment.Center
For Each C In Controls
If TypeOf C Is TextBox Then AddHandler DirectCast(C, TextBox).KeyDown, AddressOf TextBox_KeyDown
Next
End Sub
Sub Shortcuss_Pressed(ByVal sender As Shortcut)
MsgBox("Hotkey Pressed!")
'Do something..
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Hotkey set to: " & TextBox1.Text, MsgBoxStyle******rmation)
For Each C In Controls
If TypeOf C Is TextBox Then
If C.Text <> "" Then
Dim ID = Val(C.Name.Substring(7)) - 1, M(3) As Shortcut.Modifier
For I = 0 To 2
M(I) = 0
Next
If Shortcuss(ID) IsNot Nothing Then Shortcuss(ID).Unregister()
Dim X As New Shortcut
X.Register(M(0) Or M(1) Or M(2), *****nvertFromString(C.Text))
AddHandler X.Pressed, AddressOf Shortcuss_Pressed
Shortcuss(ID) = X
End If
End If
Next
End Sub
Class Shortcut : Inherits NativeWindow
Private Declare Auto Function RegisterHotKey Lib "user32" (ByVal handle As IntPtr, ByVal id As Integer, ByVal modifier As Integer, ByVal key As Integer) As Integer
Private Declare Auto Function UnregisterHotKey Lib "user32" (ByVal handle As IntPtr, ByVal id As Integer) As Integer
Enum Modifier : None = 0 : Alt = 1 : Ctrl = 2 : Shift = 4 : End Enum
Event Pressed(ByVal sender As Shortcut) : Dim ID As Integer
Sub New()
CreateHandle(New CreateParams) : ID = GetHashCode()
End Sub
Sub Register(ByVal modifier As Modifier, ByVal key As Keys)
RegisterHotKey(Handle, ID, modifier, key)
End Sub
Sub Unregister()
UnregisterHotKey(Handle, ID)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = 786 Then RaiseEvent Pressed(Me)
MyBase.WndProc(m)
End Sub
End Class
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("Hotkeys has been reset.", MsgBoxStyle******rmation)
For Each C In Controls
If TypeOf C Is TextBox Then
If C.Text <> "" Then
Dim ID = Val(C.Name.Substring(7)) - 1, M(3) As Shortcut.Modifier
For I = 0 To 2