极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8987|回复: 0

Arduino KEYBOARD (适用于莱昂纳多)

[复制链接]
发表于 2013-1-2 22:44:18 | 显示全部楼层 |阅读模式
本帖最后由 人工智能(AI) 于 2013-1-3 17:52 编辑

在Arduino网站上看到的,这个更全面。



Description

Sends a keystroke to a connected computer. This is similar to pressing and releasing a key on your keyboard. You can send some ASCII characters or the additional keyboard modifiers and special keys.

Only ASCII characters that are on the keyboard are supported. For example, ASCII 8 (backspace) would work, but ASCII 25 (Substitution) would not. When sending capital letters, Keyboard.write() sends a shift command plus the desired character, just as if typing on a keyboard. If sending a numeric type, it sends it as an ASCII character (ex. Keyboard.write(97) will send 'a').

For a complete list of ASCII characters, see ASCIITable.com.

WARNING: When you use the Keyboard.write() command, the Arduino takes over your keyboard! Make sure you have control before you use the command. A pushbutton to toggle the keyboard control state is effective.

Syntax

Keyboard.write(character)

Parameters

character : a char or int to be sent to the computer. Can be sent in any notation that's acceptable for a char. For example, all of the below are acceptable and send the same value, 65 or ASCII A:

Keyboard.write(65);         // sends ASCII value 65, or A
Keyboard.write('A');            // same thing as a quoted character
Keyboard.write(0x41);       // same thing in hexadecimal
Keyboard.write(0b01000001); // same thing in binary (weird choice, but it works)
[Get Code]

Returns

int : number of bytes sent

Example

void setup() {
  // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  //if the button is pressed
  if(digitalRead(2)==LOW){
    //Send an ASCII 'A',
    Keyboard.write(65);
  }
}
[Get Code]

See Also

    Keyboard.begin()
    Keyboard.end()
    Keyboard.press()
    Keyboard.print()
    Keyboard.println()
    Keyboard.release()
    Keyboard.releaseAll()
    ASCIITable tutorial

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.


网页:http://www.arduino.cc/en/Reference/KeyboardWrite

再贴上图




这样一替换就可以得到许多不同的按键了。
这个方法只适用于莱昂纳多,其他版本的请见我另外一个帖子。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-27 14:35 , Processed in 0.041780 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表