2012年5月8日 星期二

vb.net 輸入pn300 ( ScanCode ) (模擬輸入)



'API 宣告
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Integer

Dim SCode As Integer
V_caps_lock_stats = My.Computer.Keyboard.CapsLock '是否按下caps lock
For Ii = 1 To V_data1.Length
tmp_str = Mid(V_data1, Ii, 1) '第幾個字
SCode = MapVirtualKey(Asc(tmp_str), 0) '找出scane code
If V_caps_lock_stats = False Then
keybd_event(&H14, 0, &H0, 0) 'caps lockey down
keybd_event(&H14, 0, &H2, 0)
End If
keybd_event(Asc(tmp_str), SCode, 0, 0) '送出字串以及scan code
keybd_event(Asc(tmp_str), SCode, 2, 0) '
If V_caps_lock_stats = False Then '
keybd_event(&H14, 0, &H0, 0) 'caps lockey down
keybd_event(&H14, 0, &H2, 0) '
End If
Next
'For Ii = 1 To 200
' Threading.Thread.Sleep(1)
' Application.DoEvents()
'Next
keybd_event(13, MapVirtualKey(13, 0), &H0, 0) 'enter lockey down
keybd_event(13, MapVirtualKey(13, 0), &H2, 0)

沒有留言:

張貼留言