insert key state

  • Thread starter Thread starter Me
  • Start date Start date
M

Me

Trying to get the current status of the insert key. Found
my.computer.keyboard.capslock, but no such item for insert key. Anyone
have some code to help. Can't figure out getkeystate. compiler chokes on
rslt = getkeystate(keys.insert)
 
Me,

There are more ways in this which leads to Rome, and even an easier one than
I tell you.

But just using the keyup event gives you the possibility to set the keyboard
statuses in your program.

Cor
 
Try cutting and pasting the following class:

Public Class Keyboard
Private Declare Function GetKeyboardState Lib "user32" (ByRef pbKeyState As
Byte) As Integer
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal
bScan As Byte, ByVal dwflags As Integer, ByVal dwExtraInfo As Integer)

Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As
Integer, ByRef pInputs As GENERALINPUT, ByVal cbSize As Integer) As Integer
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef
pDst As Byte, ByRef pSrc As KEYBDINPUT, ByVal ByteLen As Integer)
<StructLayout(LayoutKind.Sequential)> Friend Structure KEYBDINPUT
Dim wVK As Short
Dim wScan As Short
Dim dwFlags As Integer
Dim time As Integer
Dim dwExtraInfo As Integer
End Structure
<StructLayout(LayoutKind.Sequential)> Friend Structure GENERALINPUT
Dim dwType As Integer
Dim wVK As Short
Dim wScan As Short
Dim dwFlags As Integer
Dim time As Integer
Dim dwExtraInfo As Integer
'Dim xi() As Byte 'dim 0 to 23
End Structure
' Constant declarations:
Const VK_NUMLOCK As Byte = &H90, vk_Scroll As Byte = &H91, vk_Capital As
Byte = &H14, vk_Ins As Byte = &H2D, vk_Shift As Byte = &H10
Const KEYEVENTF_EXTENDEDKEY As Byte = &H1, KEYEVENTF_KEYUP As Byte = &H2,
INPUT_KEYBOARD As Byte = 1
Private Shared keys(255) As Byte

Public Shared Property CapsLockOn() As Boolean
Get
Return GetKeyState(vk_Capital)
End Get
Set(ByVal Value As Boolean)
SetKeyState(vk_Capital, Value)
End Set
End Property
Public Shared Property NumLockOn() As Boolean
Get
Return GetKeyState(VK_NUMLOCK)
End Get
Set(ByVal Value As Boolean)
SetKeyState(VK_NUMLOCK, Value)
End Set
End Property
Public Shared Property ScrollLockOn() As Boolean
Get
Return GetKeyState(vk_Scroll)
End Get
Set(ByVal Value As Boolean)
SetKeyState(vk_Scroll, Value)
End Set
End Property
Public Shared Property InsertModeOn() As Boolean
Get
Return GetKeyState(vk_Ins)
End Get
Set(ByVal Value As Boolean)
SetKeyState(vk_Ins, Value)
End Set
End Property

Private Shared Function GetKeyState(ByVal keycode As Short) As Boolean
GetKeyboardState(keys(0))
Return (keys(keycode) And 1) > 0
End Function
Private Shared Sub SetKeyState(ByVal Keycode As Byte, ByVal Value As Boolean)
GetKeyboardState(keys(0))
If Value <> ((keys(Keycode) And 1) > 0) Then
'Key Press
keybd_event(Keycode, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)
'Key Release
keybd_event(Keycode, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
End If
End Sub
End Class
 
Thanks Dennis. Appreciate the good help. Kinda answered some other
questions such as howto also.
thanks again...Smitty
 
Back
Top