Arduino Leonardoのkeyboard.press()でシフトキーを押した時の記号について。
以下のスケッチを使う。ピン2とGNDに繋いだスイッチを押すと[SHIFT]+[2]が出力される。
これを以下の環境で確認した。SHIFT+2では……
MacOSX Lion/PowerBookPro13インチ 日本語キーボード : @マーク
Windows7 32bit DELL PRECISION4300 英語キーボード : @マーク
WindowsXP DELL Latitude D630 日本語キーボード : ”マーク
Windows環境では本体のキーボードを押すのと同じ様に入力された。
MacOSXではLeonardoをUSBで接続した時にHIDキーボードの識別をする画面が出るが、これをキャンセルすると英語配列として扱うようだ。
以下のスケッチを使う。ピン2とGNDに繋いだスイッチを押すと[SHIFT]+[2]が出力される。
/*
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int keymacroPin = 3;
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
pinMode(keymacroPin, INPUT_PULLUP);
Keyboard.begin();
}
void loop(){
if (digitalRead(keymacroPin)==LOW) {
// not implemented
}
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(ledPin, HIGH);
delay(30);
while(buttonState == LOW){
buttonState = digitalRead(buttonPin);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press('2');
}
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
Keyboard.release('2');
Keyboard.release(KEY_LEFT_SHIFT);
}
delay(100);
}
これを以下の環境で確認した。SHIFT+2では……
MacOSX Lion/PowerBookPro13インチ 日本語キーボード : @マーク
Windows7 32bit DELL PRECISION4300 英語キーボード : @マーク
WindowsXP DELL Latitude D630 日本語キーボード : ”マーク
Windows環境では本体のキーボードを押すのと同じ様に入力された。
MacOSXではLeonardoをUSBで接続した時にHIDキーボードの識別をする画面が出るが、これをキャンセルすると英語配列として扱うようだ。









