[Tut]advanced hotkey system[Open Source]
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:
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 = T.ConvertToString(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), T.ConvertFromString(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
M(I) = 0
Next
Shortcuss(ID).Unregister()
End If
End If
Next
End Sub
End Class
[/php]
Virusscans:
Virustotal. MD5: ffe737b2d1e871cd5af684cacfce3bae
Virscan doesnt let me scan the .rar
Hope you like it
-hej

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 = T.ConvertToString(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), T.ConvertFromString(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
M(I) = 0
Next
Shortcuss(ID).Unregister()
End If
End If
Next
End Sub
End Class
[/php]
Virusscans:
Virustotal. MD5: ffe737b2d1e871cd5af684cacfce3bae
Virscan doesnt let me scan the .rar
Hope you like it

-hej
Hejsan and Aoen hotkey system[Open Source] .rar



