Toggle Keyboard Insert key

jdlc

Registered User.
Local time
Today, 03:45
Joined
Mar 26, 2013
Messages
56
is there a way in vba we can check the status of Insert key if it is on or off when the form is loaded?

i want for the insert key to be on, where the key strokes write over the existing entry.

i do set the key preview to "yes" in the form, and it works fine, but i wanted it only on a specific object.
 
currently i use this codes, just to check the status of the Insert Key

in a module:

Code:
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) _
As Integer

and call it:

Code:
GetKeyState(vbKeyInsert)

what i want is how to turn it on in a specific object.
 
found it!

Code:
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long

Function GetCapslock() As Boolean
' Return or set the Capslock toggle.
GetCapslock = CBool(GetKeyState(vbKeyCapital) And 1)
End Function

Function GetNumlock() As Boolean
' Return or set the Numlock toggle.
GetNumlock = CBool(GetKeyState(vbKeyNumlock) And 1)
End Function

Function GetScrollLock() As Boolean
' Return or set the ScrollLock toggle.
GetScrollLock = CBool(GetKeyState(vbKeyScrollLock) And 1)
End Function

Sub SetCapslock(Value As Boolean)
' Return or set the Capslock toggle.
Call SetKeyState(vbKeyCapital, Value)
End Sub

Sub SetNumlock(Value As Boolean)
' Return or set the Numlock toggle.
Call SetKeyState(vbKeyNumlock, Value)
End Sub

Sub SetScrollLock(Value As Boolean)
' Return or set the ScrollLock toggle.
Call SetKeyState(vbKeyScrollLock, Value)
End Sub

Private Sub SetKeyState(intKey As Integer, fTurnOn As Boolean)
' Retrieve the keyboard state, set the particular
' key in which you're interested, and then set
' the entire keyboard state back the way it
' was, with the one key altered.
Dim abytBuffer(0 To 255) As Byte
GetKeyboardState abytBuffer(0)
abytBuffer(intKey) = CByte(Abs(fTurnOn))
SetKeyboardState abytBuffer(0)
End Sub
 

Users who are viewing this thread

Back
Top Bottom