232串口扫描q如何设置成键盘口

232串口扫描q如何设置成键盘口,第1张

你的问题有两种解决办法:

1、更换扫描器数据线,换成键盘口或者USB接口的数据线,并设置成对应的接口类型。

2、因为232串口类型的扫描q,扫描条码得到的数据,不能自己显示在当前光标位置。需要在网上下载一个串口扫描的小程序COM2KEY,将串口扫描器模拟成键盘口接口。

如果你可以用串口的话可以看一下扫描q是怎么做的。如果你自己写程序,可以参考一下代码把收到的数据与键盘映射起来

Option Explicit

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const VK_ADD As Long = &H6B '加号键

Private Const VK_APPS As Long = &H5D 'Applications 键(相当于鼠标右键)

Private Const VK_BACK As Long = &H8 'BackSpace 键

Private Const VK_CAPITAL As Long = &H14 'Caps Lock 键(大小写转换键)

Private Const VK_CANCEL As Long = &H3'Ctrl + Break 过程

Private Const VK_CONTROL As Long = &H11

Private Const VK_DECIMAL As Long = &H6E '小数点号键

Private Const VK_DELETE As Long = &H2E

Private Const VK_DIVIDE As Long = &H6F '除号键

Private Const VK_DOWN As Long = &H28

Private Const VK_END As Long = &H23

Private Const VK_ESCAPE As Long = &H1B

Private Const VK_F1 As Long = &H70

Private Const VK_F10 As Long = &H79

Private Const VK_F11 As Long = &H7A

Private Const VK_F12 As Long = &H7B

Private Const VK_F2 As Long = &H71

Private Const VK_F3 As Long = &H72

Private Const VK_F4 As Long = &H73

Private Const VK_F5 As Long = &H74

Private Const VK_F6 As Long = &H75

Private Const VK_F7 As Long = &H76

Private Const VK_F8 As Long = &H77

Private Const VK_F9 As Long = &H78

Private Const VK_HOME As Long = &H24

Private Const VK_INSERT As Long = &H2D

Private Const VK_LCONTROL As Long = &HA2

Private Const VK_LEFT As Long = &H25

Private Const VK_LMENU As Long = &HA4'左 Alt 键

Private Const VK_LSHIFT As Long = &HA0

Private Const VK_LWIN As Long = &H5B

Private Const VK_MENU As Long = &H12 'Alt 键

Private Const VK_MULTIPLY As Long = &H6A '乘号键

Private Const VK_NEXT As Long = &H22 '下翻页键

Private Const VK_NUMLOCK As Long = &H90

Private Const VK_NUMPAD0 As Long = &H60

Private Const VK_NUMPAD1 As Long = &H61

Private Const VK_NUMPAD2 As Long = &H62

Private Const VK_NUMPAD3 As Long = &H63

Private Const VK_NUMPAD4 As Long = &H64

Private Const VK_NUMPAD5 As Long = &H65

Private Const VK_NUMPAD6 As Long = &H66

Private Const VK_NUMPAD7 As Long = &H67

Private Const VK_NUMPAD8 As Long = &H68

Private Const VK_NUMPAD9 As Long = &H69

Private Const VK_PAUSE As Long = &H13

Private Const VK_PRINT As Long = &H2A

Private Const VK_PRIOR As Long = &H21'上翻页键

Private Const VK_RCONTROL As Long = &HA3

Private Const VK_RETURN As Long = &HD'回车键

Private Const VK_RIGHT As Long = &H27

Private Const VK_RMENU As Long = &HA5'右 Alt 键

Private Const VK_RSHIFT As Long = &HA1

Private Const VK_RWIN As Long = &H5C

Private Const VK_SCROLL As Long = &H91 'Scroll Lock 键

Private Const VK_SEPARATOR As Long = &H6C'小键盘上的回车键

Private Const VK_SHIFT As Long = &H10

Private Const VK_SLEEP As Long = &H5F'休眠键

Private Const VK_SNAPSHOT As Long = &H2C 'Print Screen 键

Private Const VK_SPACE As Long = &H20

Private Const VK_SUBTRACT As Long = &H6D '减号键

Private Const VK_TAB As Long = &H9

Private Const VK_UP As Long = &H26

Private Const VK_OEM_1 As Long = &HBA'Windows 2000:对于 US 标准键盘,是“:”键

Private Const VK_OEM_2 As Long = &HBF'Windows 2000:对于 US 标准键盘,是“/?”键

Private Const VK_OEM_3 As Long = &HC0'Windows 2000:对于 US 标准键盘,是“`~”键

Private Const VK_OEM_4 As Long = &HDB'Windows 2000:对于 US 标准键盘,是“[{”键

Private Const VK_OEM_5 As Long = &HDC'Windows 2000:对于 US 标准键盘,是“\|”键

Private Const VK_OEM_6 As Long = &HDD'Windows 2000:对于 US 标准键盘,是“]}”键

Private Const VK_OEM_7 As Long = &HDE'Windows 2000:对于 US 标准键盘,是“单/双引号”键

Private Const VK_OEM_COMMA As Long = &HBC'Windows 2000:对于任何国家/地区,是“,”键

Private Const VK_OEM_MINUS As Long = &HBD'Windows 2000:对于任何国家/地区,是“-”键

Private Const VK_OEM_PERIOD As Long = &HBE 'Windows 2000:对于任何国家/地区,是“.”键

Private Const VK_OEM_PLUS As Long = &HBB 'Windows 2000:对于任何国家/地区,是“+”键

Private Const KEYEVENTF_KEYUP = &H2

程序示例:

Option Explicit

'模拟键盘函数

Private Declare Sub keybd_event Lib "user32" _

(ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

'根据指定的映射类型,执行不同的扫描码和字符转换,0—— wCode是个虚拟键码。函数返回相应的扫描码

Private Declare Function MapVirtualKey Lib "user32" _

Alias "MapVirtualKeyA" _

(ByVal wCode As Long, _

ByVal wMapType As Long) _

As Long

Private Const VK_CONTROL = &H11

Private Const KEYEVENTF_KEYUP = &H2

Private Const VK_RETURN = &HD

Private Sub Command1_Click()

Unload Me

End Sub

Private Sub Form_click()

If Clipboard.GetFormat(vbCFText) Then

keybd_event VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0'起动ctrl

keybd_event Asc("V"), MapVirtualKey(Asc("V"), 0), 0, 0 '模拟按下"V"键,此处为ascll码

keybd_event Asc("V"), MapVirtualKey(Asc("V"), 0), KEYEVENTF_KEYUP, 0 '撤消按下的V键

keybd_event VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0 '撤消ctrl

'以下两句主要是为了换行看清楚,可以删除

keybd_event VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0 '模拟回车

keybd_event VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0'撤消回车

Else

MsgBox "剪切板内容不是文本格式"

End If


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7761121.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-09
下一篇 2023-04-09

发表评论

登录后才能评论

评论列表(0条)

保存