Hello guys.
I am facing an issue using some piece of code to create a hotkey
This is what I have which works fine (Checkbox is turnes on/off)
Module:
Form Code:Code:Public Declare Function GetAsyncKeyState Lib "USER32" _ (ByVal vKey As Int32) _ As Int16
Now, instead of a BUTTON, I use the following code to create a keyboard eventCode:Public Class Form1 Dim hotkey As Boolean Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load hotkey=true End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If hotkey = True Then CheckBox1.Checked = True hotkey = False Else CheckBox1.Checked = False hotkey = True End If End Sub End Class
With this code, checkbox is turned on while NumPad1 is holding down. When I let it go, is turned offCode:Private Sub KeyLogger_Tick() Handles KeyLogger.Tick Dim hotkey As Boolean hotkey = GetAsyncKeyState(Keys.NumPad1) If hotkey = True Then CheckBox1.Checked = True hotkey = False Else CheckBox1.Checked = False hotkey = True End If End Sub
How can I make checkbox turned on when NumPad1 is pressed once, and turned it off when NumPad1 is pressed once again?




Reply With Quote
