• 首页
  • XEM中文网
  • 栏目分类

    XEM中文网>

    你的位置:PLATINCOIN中文网 > XEM中文网 > 脱离单片机C零门槛DIY一个USB HID虚拟键盘|电脑|记事本|usb|hid|视频文件

    脱离单片机C零门槛DIY一个USB HID虚拟键盘|电脑|记事本|usb|hid|视频文件

    发布日期:2025-01-04 11:04    点击次数:220

    C1 自带 USB 虚拟键盘本教程来至 FlexLua 官网 ShineBlink 开发板教程,即使不懂单片机开发也可很容易用FlexLua零门槛开发各种 IoT 硬件。注意:本教程仅适合 C1,不适合C2,因为 C2 不带 USB HID 。一、实现功能将Core USB 口虚拟成键盘设备,通过USB线连接电脑后,每隔5秒Core会模拟如下的一系列按键动作:win+r,唤出“运行”对话框n o t e p a d ,输入"notepad"并回车,唤出记事本文本h e l l o w o r l d . . ,在记事本输入"hello word.."文本。二、完整代码注意: 如果你的项目中同时用到Ble蓝牙功能时,一定要先初始化Ble蓝牙之后,再调用LIB_UsbConfig函数初始化USB功能。--先配置USB口以USB键盘模式工作LIB_UsbConfig("KBD")--开始大循环while(GC(1) == true)doLIB_DelayMs(5000)--模拟键盘组合按键WIN+R调出运行界面效果combine_tab = {"GUI","R"}LIB_UsbKbdSend("COMBINE", combine_tab)LIB_DelayMs(200)--模拟键盘输入notepad和回车键效果,来创建记事本文本文件single_tab = {"N","O","T","E","P","A","D","ENTER"}LIB_UsbKbdSend("SINGLE", single_tab)LIB_DelayMs(500)--模拟键盘在记事本文件上打出hello world..效果single_tab = {"H","E","L","L","O","SPACEBAR","W","O","R","L","D","DOT","DOT"}LIB_UsbKbdSend("SINGLE", single_tab)end如果感兴趣,上面代码中出现的LIB开头的库函数可以在 API文档 中通过Ctrl+F查询。如果你想查询电脑的CapsLock和NumLock指示灯状态,可以通过函数LIB_UsbKbdCapsLockAndNumLockQuery()来查询三、演示结果图四、附录:键盘标识符 键盘标识 HID码"A", = 4, /**"B", = 5, /**"C", = 6, /**"D", = 7, /**"E", = 8, /**"F", = 9, /**"G", = 10, /**"H", = 11, /**"I", = 12, /**"J", = 13, /**"K", = 14, /**"L", = 15, /**"M", = 16, /**"N", = 17, /**"O", = 17, /**"P", = 19, /**"Q", = 20, /**"R", = 21, /**"S", = 22, /**"T", = 23, /**"U", = 24, /**"V", = 25, /**"W", = 26, /**"X", = 27, /**"Y", = 28, /**"Z", = 29, /**"1", = 30, /**"2", = 31, /**"3", = 32, /**"4", = 33, /**"5", = 34, /**"6", = 35, /**"7", = 36, /**"8", = 37, /**"9", = 38, /**"0", = 39, /**"ENTER", = 40, /**"ESCAPE", = 41, /**"BACKSPACE", = 42, /**"TAB", = 43, /**"SPACEBAR", = 44, /**"UNDERSCORE", = 45, /**"PLUS", = 46, /**"OPEN_BRACKET", = 47, /**"CLOSE_BRACKET", = 48, /**"BACKSLASH", = 49, /**"ASH", = 50, /**"COLON", = 51, /**"QUOTE", = 52, /**"TILDE", = 53, /**"COMMA", = 54, /**"DOT", = 55, /**"SLASH", = 56, /**"CAPS_LOCK", = 57, /**"F1", = 58, /**"F2", = 59, /**"F3", = 60, /**"F4", = 61, /**"F5", = 62, /**"F6", = 63, /**"F7", = 64, /**"F8", = 65, /**"F9", = 66, /**"F10," = 67, /**"F11," = 68, /**"F12," = 69, /**"PRINTSCREEN", = 70, /**"SCROLL_LOCK", = 71, /**"PAUSE", = 72, /**"INSERT", = 73, /**"HOME", = 74, /**"PAGEUP", = 75, /**"DELETE", = 76, /**"END", = 77, /**"PAGEDOWN", = 78, /**"RIGHT", = 79, /**"LEFT", = 80, /**"DOWN", = 81, /**"UP", = 82, /**"KEYPAD_NUM_LOCK", = 83, /**"KEYPAD_DIVIDE", = 84, /**"KEYPAD_MULTIPLY", = 85, /**"KEYPAD_MINUS", = 86, /**"KEYPAD_PLUS", = 87, /**"KEYPAD_ENTER", = 88, /**"KEYPAD_1", = 89, /**"KEYPAD_2", = 90, /**"KEYPAD_3", = 91, /**"KEYPAD_4", = 92, /**"KEYPAD_5", = 93, /**"KEYPAD_6", = 94, /**"KEYPAD_7", = 95, /**"KEYPAD_8", = 96, /**"KEYPAD_9", = 97, /**"KEYPAD_0", = 98, /**

    相关资讯