Keyboard.press()
描述
送出按下键盘按键的命令给已连接的电脑(相当于按着键盘按键不放),您也可以配合修饰键来使用。若要放开键盘按键,请呼叫 Keyboard.release() 函式,或者 Keyboard.releaseAll() 函式。
在呼叫 Keyboard.press()
函式之前,要先呼叫 Keyboard.begin() 函式。
语法
Keyboard.press(key)
参数
key
: 要按下的按键(char 型别)
回传
无回传值
范例
// 在 OSX 系统中使用的 ctrl 按键: char ctrlKey = KEY_LEFT_GUI; // 在 Windows 或 Linux 下使用的 ctrl 按键: // char ctrlKey = KEY_LEFT_CTRL; void setup() { // 将 pin 2 设定为 INPUT_PULLUP 状态 // 这样它就会在外部按钮被按下时 // 呈现 LOW 的状态 pinMode(2, INPUT_PULLUP); // 开始 HID 键盘模拟 Keyboard.begin(); } void loop() { while (digitalRead(2) == HIGH) { // 不做任何事情直到 pin 2 为 LOW delay(500); } delay(1000); // 在 IDE 上打开新的分页 Keyboard.press(ctrlKey); Keyboard.press('n'); delay(100); Keyboard.releaseAll(); // 等待新的分页开启 delay(1000); }
See also
- Keyboard.begin()
- Keyboard.end()
- Keyboard.print()
- Keyboard.println()
- Keyboard.release()
- Keyboard.releaseAll()
- Keyboard.write()
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.