[DllImport("user32.dll")]
static extern short GetKeyState(int nVirtKey);
Here are some sample values for nVirtKey:
const int VK_SHIFT = 0x10;
const int VK_CONTROL = 0x11;
const int VK_MENU = 0x12;
The Enum Keys in System.Windows.Forms has the key code used for this function, so you don't need to define const
This Sample use this API to create a new textbox to support overwrite mode, testing the state of insert key.
Imports System.Windows.Forms
Public Class MinhaNovaTextbox
Inherits System.Windows.Forms.TextBox
Dim bInserting As Boolean = True
Private Declare Function GetKeyState _
Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Sub New()
MyBase.New()
bInserting = GetKeyState(Keys.Insert)
End Sub
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
bInserting = GetKeyState(Keys.Insert)
If Not bInserting Then
Me.SelectionLength = 1
End If
MyBase.OnKeyPress(e)
End Sub
End Class
Do you know one? Please contribute it!