'https://support.microsoft.com/zh-tw/kb/179987
'Resolution:
'Determine the setting of the NumLock key prior to using SendKeys.
'Then, turn off the NumLock before using SendKeys.
'After using SendKeys,reset the NumLock to its previous setting.
'This is accomplished using the GetKeyboardState, keybd_event and SetKeyboardState API functions.
'================================================================================================
Private Sub test() '測試 sendkeys
presetNumlock
SendKeys "^g^a{DEL}" ', True
TurnNumlock
End Sub
Sub presetNumlock()
Dim bKeys(0 To 255) As Byte
Dim LockState%
'Get status of the 256 virtual keys
GetKeyboardState bKeys(0)
'turn off the num_lock key
If bKeys(vbKeyNumlock) = 1 Then
TurnNumlock
End If
DoEvents '一定要 ?
Public Sub Sendkey2(keyArray)
For w = LBound(keyArray) To UBound(keyArray): Call keybd_event(keyArray(w), 0, &H1, 0): Next
For w = LBound(keyArray) To UBound(keyArray): Call keybd_event(keyArray(w), 0, &H3, 0): Next
End Sub
Public Sub clear_win ( )
Sendkey2 Array(vbKeyControl, vbKeyG)
Sendkey2 Array(vbKeyControl, vbKeyA)
Sendkey2 Array(vbKeyDelete)
If GetKeyState(vbKeyNumlock) = 1 Then
Sendkey2 Array(vbKeyNumlock)
End If
End Sub作者: Scott090 時間: 2016-9-27 14:40