Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27186

VS 2010 I don't know how easy this will be to answer...

$
0
0
I want to let users choose their own hot key to use when starting my program but I am not sure how to do it and I THOUGHT it may look something like this but it wasn't working.
Code:

Imports System.Runtime.InteropServices

Public Class Form1
    Public Const WM_HOTKEY As Integer = &H312

    <DllImport("User32.dll")> _
    Public Shared Function RegisterHotKey(ByVal hwnd As IntPtr, _
                        ByVal id As Integer, ByVal fsModifiers As Integer, _
                        ByVal vk As Integer) As Integer
    End Function

    <DllImport("User32.dll")> _
    Public Shared Function UnregisterHotKey(ByVal hwnd As IntPtr, _
                        ByVal id As Integer) As Integer
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, _
                        ByVal e As System.EventArgs) Handles MyBase.Load
        RegisterHotKey(Me.Handle, 100, Nothing, Keys.(TextBox1.Text))
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_HOTKEY Then
            Dim id As IntPtr = m.WParam
            Select Case (id.ToString)
                Case "100"
                    If Not Timer1.Enabled Then
                        Timer1.Start()
                    ElseIf Timer1.Enabled Then
                        Timer1.Stop()
                    End If
            End Select
        End If
        MyBase.WndProc(m)
    End Sub
End Class

The error I get for using that code is "Identifier expected." I thought that if someone were to add "F12" to that box it may use F12 as the hotkey but that isn't the case.

Question: "How would I make it so that if you click a button a input box would pop up and you could hold in any keys you want WHILE the input box is open and my program would make whatever keys you held in appear in the input box and THEN when you press OK they appear in a textbox THEN if you hold all of those keys down at the same time a timer would start."

See code above.

Viewing all articles
Browse latest Browse all 27186

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>