VB.Net Mirroring AHK HotKey Functionality

Discuss other programming languages besides AutoHotkey
The_Wildry_Dude
Posts: 11
Joined: 17 Aug 2015, 17:15

VB.Net Mirroring AHK HotKey Functionality

30 Sep 2016, 11:09

Hey everyone -

I'm trying to emulate the hotkey functionality in AHK with VB.Net. Basically, mirror it identically. I'm not entirely sure how to get started. I did get something basic operational, however, it's a far cry from AHK's awesome native functionality. This will be developed for windows.

VB.NET Code

Code: Select all

Imports System.Runtime.InteropServices
Imports System.Timers

Public Class Form1
    Private Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Integer) As Integer

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer1.Interval = 1
    End Sub

    Private Sub Timer1_Tick(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If GetKeyPress(Keys.A) And GetKeyPress(Keys.Enter) Then
            MsgBox("A And Enter Pressed")
            Exit Sub
        End If
    End Sub
End Class
Currently, this only works when I press all the keys together (pressed at once). How can I make it work by pressing the last key in the sequence to kick off the hotkey. Additionally, how would I add termination keys, like 'Enter' and 'Space' that kick off the hotkey.

Looking for a nudge, or an example to get started.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: VB.Net Mirroring AHK HotKey Functionality

15 Nov 2016, 03:12

"Polling" (or in other words, continuously and repeatedly checking the state of each key) is possibly the worst way to implement a hotkey.

I suggest you look for some existing VB.NET (or other .NET) code which uses RegisterHotkey or a keyboard hook (keyword: WH_KEYBOARD_LL).

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 13 guests