int count = 0; void setup() { } // no setup needed void loop() { delay(1000); //Keyboard.print("HI,I am Tony!"); delay(1000); RunPro("cmd"); Keyboard.set_key1(KEY_ENTER); Keyboard.send_now(); RSTkey(); CloseInputMethod(); delay(1000); Keyboard.set_key1(KEY_ENTER); Keyboard.send_now(); Keyboard.print("ping baidu.com"); Keyboard.set_key1(KEY_ENTER); Keyboard.send_now(); RSTkey(); delay(5000000); } void RSTkey(){ //release key Keyboard.set_modifier(0);//release ctrl or shift etc. Keyboard.set_key1(0);//release normal key Keyboard.send_now(); //release key ok } void Count(){ count = count + 1; } void RunPro(String ProName){ Keyboard.set_modifier(MODIFIERKEY_GUI); Keyboard.set_key1(KEY_R); Keyboard.send_now(); RSTkey(); delay(100); CloseInputMethod(); Keyboard.print(ProName); delay(30); Keyboard.set_key1(KEY_ENTER); Keyboard.send_now(); RSTkey(); delay(1000); } void CloseInputMethod(){ Keyboard.set_modifier(MODIFIERKEY_CTRL); Keyboard.send_now(); Keyboard.set_key1(KEY_SPACE); Keyboard.send_now(); RSTkey(); delay(1000); Keyboard.set_modifier(MODIFIERKEY_SHIFT); Keyboard.send_now(); RSTkey(); delay(100); }
分类:硬件开发
Teensy键盘操作代码说明
int count = 0; void setup() { } // no setup needed void loop() { Keyboard.print("Hello World "); Keyboard.println(count); count = count + 1; //press key a Keyboard.set_key1(KEY_A); Keyboard.send_now(); //press key now //release key Keyboard.set_modifier(0);//release ctrl or shift etc. Keyboard.set_key1(0);//release normal key Keyboard.send_now(); //release key ok delay(5000); }
Teensy 键盘按键一览表
All Keys Codes
Normal Keys | |||
---|---|---|---|
KEY_A | KEY_B | KEY_C | KEY_D |
KEY_E | KEY_F | KEY_G | KEY_H |
KEY_I | KEY_J | KEY_K | KEY_L |
KEY_M | KEY_N | KEY_O | KEY_P |
KEY_Q | KEY_R | KEY_S | KEY_T |
KEY_U | KEY_V | KEY_W | KEY_X |
KEY_Y | KEY_Z | KEY_1 | KEY_2 |
KEY_3 | KEY_4 | KEY_5 | KEY_6 |
KEY_7 | KEY_8 | KEY_9 | KEY_0 |
KEY_ENTER | KEY_ESC | KEY_BACKSPACE | KEY_TAB |
KEY_SPACE | KEY_MINUS | KEY_EQUAL | KEY_LEFT_BRACE |
KEY_RIGHT_BRACE | KEY_BACKSLASH | KEY_NUMBER | KEY_SEMICOLON |
KEY_QUOTE | KEY_TILDE | KEY_COMMA | KEY_PERIOD |
KEY_SLASH | KEY_CAPS_LOCK | KEY_F1 | KEY_F2 |
KEY_F3 | KEY_F4 | KEY_F5 | KEY_F6 |
KEY_F7 | KEY_F8 | KEY_F9 | KEY_F10 |
KEY_F11 | KEY_F12 | KEY_PRINTSCREEN | KEY_SCROLL_LOCK |
KEY_PAUSE | KEY_INSERT | KEY_HOME | KEY_PAGE_UP |
KEY_DELETE | KEY_END | KEY_PAGE_DOWN | KEY_RIGHT |
KEY_LEFT | KEY_DOWN | KEY_UP | KEY_NUM_LOCK |
KEYPAD_SLASH | KEYPAD_ASTERIX | KEYPAD_MINUS | KEYPAD_PLUS |
KEYPAD_ENTER | KEYPAD_1 | KEYPAD_2 | KEYPAD_3 |
KEYPAD_4 | KEYPAD_5 | KEYPAD_6 | KEYPAD_7 |
KEYPAD_8 | KEYPAD_9 | KEYPAD_0 | KEYPAD_PERIOD |
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
CTRL和ALT一起按用竖线(|)隔开
Name | Function |
---|---|
MODIFIERKEY_CTRL | Control Key |
MODIFIERKEY_SHIFT | Shift Key |
MODIFIERKEY_ALT | Alt Key |
MODIFIERKEY_GUI | Windows (PC) or Clover (Mac) |
Teensy键盘模拟示例代码
int count = 0; void setup() { } // no setup needed void loop() { Keyboard.print("Hello World "); Keyboard.println(count); count = count + 1; delay(503); }