By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
You need to call the Win32 GetKeyState function. The following program snippet shows how to call it. Note that I did not include the form layout code in the sample.
Imports System.Runtime.InteropServices Public Class Win32 Declare Auto Function GetKeyState Lib "user32.dll" _ (ByVal nVirtKey As Integer) As Integer End Class Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Button1.Click ' &H2D is VK_INSERT. Dim x As Integer = Win32.GetKeyState(&H2D) If (&H1 = (&H1 And x)) Then Label1.Text = "Insert key down" Else Label1.Text = "Insert key up" End If End Sub End Class
Dig Deeper on Win Development Resources
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.