Arduino UNO R4 WiFi USB HID

Started by tha, November 01, 2023, 08:37:46 AM

Previous topic - Next topic

tha


tha

Learn more

คุณสามารถค้นหาบทช่วยสอนพื้นฐานเพิ่มเติมได้ใน the built-in examples section.

คุณยังสามารถสำรวจ the language reference, ซึ่งเป็นคอลเล็กชันรายละเอียดของ the Arduino programming language.

แก้ไขครั้งล่าสุด  2015/07/29 by SM

tha

https://docs.arduino.cc/built-in-examples/usb/KeyboardLogout

Keyboard Logout

ออกจากระบบผู้ใช้ปัจจุบันด้วย key commands.

LAST REVISION: 31/10/2566 21:11

ตัวอย่างนี้ใช้ the Keyboard library เพื่อนำคุณออกจาก user session ของคุณบนคอมพิวเตอร์ของคุณเมื่อ pin 2 บน Leonardo, Micro หรือ Due ของคุณถูกดึงลงกราวน์ The sketch จะจำลองการกดปุ่มตามลำดับปุ่มสองหรือสามปุ่มพร้อมกัน และหลังจากนั้นครู่หนึ่งก็จะปล่อยปุ่มเหล่านั้น

หมายเหตุ: เมื่อคุณใช้คำสั่ง Keyboard.print(), the Arduino จะเข้ามาแทนที่คีย์บอร์ดของคอมพิวเตอร์ของคุณ! เพื่อให้แน่ใจว่าคุณจะไม่สูญเสียการควบคุมคอมพิวเตอร์ของคุณในขณะที่กำลังใช้งาน a sketch ด้วยฟังก์ชันนี้ ตรวจสอบให้แน่ใจว่าได้ตั้งค่าระบบควบคุมที่เชื่อถือได้ก่อนที่จะเรียก Keyboard.print() sketch นี้ถูกออกแบบเฉพาะส่ง a Keyboard command หลังจาก a pin ถูกดึงลงกราวน์แล้วเท่านั้น.


tha

Hardware Required

  •  Arduino Leonardo, Micro, or Due board
  •  pushbutton
  •  hook-up wires
  •  breadboard

Circuit



Schematic


tha

Code

ก่อนที่คุณจะอัพโหลดโปรแกรมไปยังบอร์ดของคุณ ตรวจสอบให้แน่ใจว่าได้กำหนด OS ที่ถูกต้องที่คุณกำลังใช้อยู่ให้กับ the platform variable.

ในขณะที่ the sketch กำลังทำงาน การกดปุ่มจะเชื่อมต่อ pin 2 เข้ากับกราวด์ และบอร์ดจะส่ง the logout sequence ไปยังพีซีที่เชื่อมต่อ USB

/*

  Keyboard logout

  This sketch demonstrates the Keyboard library.

  When you connect pin 2 to ground, it performs a logout.

  It uses keyboard combinations to do this, as follows:

  On Windows, CTRL-ALT-DEL followed by ALT-l

  On Ubuntu, CTRL-ALT-DEL, and ENTER

  On OSX, CMD-SHIFT-q

  To wake: Spacebar.

  Circuit:

  - Arduino Leonardo or Micro

  - wire to connect D2 to ground

  created 6 Mar 2012

  modified 27 Mar 2012

  by Tom Igoe

  This example is in the public domain.

  https://www.arduino.cc/en/Tutorial/KeyboardLogout

*/

#define OSX 0
#define WINDOWS 1
#define UBUNTU 2

#include "Keyboard.h"

// change this to match your platform:
int platform = OSX;

void setup() {

  // make pin 2 an input and turn on the pull-up resistor so it goes high unless

  // connected to ground:

  pinMode(2, INPUT_PULLUP);

  Keyboard.begin();
}

void loop() {

  while (digitalRead(2) == HIGH) {

    // do nothing until pin 2 goes low

    delay(500);

  }

  delay(1000);

  switch (platform) {

    case OSX:

      Keyboard.press(KEY_LEFT_GUI);

      // Shift-Q logs out:

      Keyboard.press(KEY_LEFT_SHIFT);

      Keyboard.press('Q');

      delay(100);

      Keyboard.releaseAll();

      // enter:

      Keyboard.write(KEY_RETURN);

      break;

    case WINDOWS:

      // CTRL-ALT-DEL:

      Keyboard.press(KEY_LEFT_CTRL);

      Keyboard.press(KEY_LEFT_ALT);

      Keyboard.press(KEY_DELETE);

      delay(100);

      Keyboard.releaseAll();

      // ALT-l:

      delay(2000);

      Keyboard.press(KEY_LEFT_ALT);

      Keyboard.press('l');

      Keyboard.releaseAll();

      break;

    case UBUNTU:

      // CTRL-ALT-DEL:

      Keyboard.press(KEY_LEFT_CTRL);

      Keyboard.press(KEY_LEFT_ALT);

      Keyboard.press(KEY_DELETE);

      delay(1000);

      Keyboard.releaseAll();

      // Enter to confirm logout:

      Keyboard.write(KEY_RETURN);

      break;

  }

  // do nothing:

  while (true);
}

tha

Learn more

คุณสามารถค้นหาบทช่วยสอนพื้นฐานเพิ่มเติมได้ใน the built-in examples section.

คุณยังสามารถสำรวจ the language reference, ซึ่งเป็นคอลเล็กชันรายละเอียดของ the Arduino programming language.

แก้ไขครั้งล่าสุด  2015/07/29 by SM

tha

https://docs.arduino.cc/built-in-examples/usb/KeyboardSerial

Keyboard Serial

อ่าน a byte จาก the serial port, และส่งกลับ a keystroke.

LAST REVISION: 31/10/2566 21:11

ตัวอย่างนี้ฟัง a byte ที่มาจาก the serial port เมื่อได้รับ, บอร์ดจะส่งการกดแป้นพิมพ์กลับไปยังคอมพิวเตอร์ การกดแป้นพิมพ์ที่ส่งไปนั้นสูงกว่าที่ได้รับหนึ่ง ดังนั้น หากคุณส่ง "a" จาก the serial monitor, คุณจะได้รับ "b" จากบอร์ดที่เชื่อมต่อกับคอมพิวเตอร์ "1" จะส่งกลับ "2" และต่อๆ ไป

หมายเหตุ: เมื่อคุณใช้คำสั่ง Keyboard.print(), the Leonardo, Micro หรือ Due board จะเข้ามาแทนที่คีย์บอร์ดของคอมพิวเตอร์ของคุณ! เพื่อให้แน่ใจว่าคุณจะไม่สูญเสียการควบคุมคอมพิวเตอร์ของคุณในขณะที่กำลังรัน a sketch ด้วยฟังก์ชันนี้ ตรวจสอบให้แน่ใจว่าได้ตั้งค่าระบบควบคุมที่เชื่อถือได้ก่อนที่จะเรียก Keyboard.print() sketch นี้ถูกออกแบบเฉพาะส่ง a Keyboard command หลังจาก the board ได้รับ a byte จาก the serial port แล้วเท่านั้น.

tha

Hardware Required

  •  Arduino Leonardo, Micro, or Due board

Circuit

ต่อ board ของคุณเข้ากับ computer ของคุณด้วย a micro-USB cable.

เมื่อโปแกรมแล้ว, เปิด serial monitor ของคุณและส่ง a byte. The board จะตอบด้วย a keystroke ที่สูงกว่าหนึ่งหมายเลข.



Code

/*

  Keyboard test

  For the Arduino Leonardo, Micro or Due

  Reads a byte from the serial port, sends a keystroke back.

  The sent keystroke is one higher than what's received, e.g. if you send a,

  you get b, send A you get B, and so forth.

  The circuit:

  - none

  created 21 Oct 2011

  modified 27 Mar 2012

  by Tom Igoe

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/KeyboardSerial

*/

#include "Keyboard.h"

void setup() {

  // open the serial port:

  Serial.begin(9600);

  // initialize control over the keyboard:

  Keyboard.begin();
}

void loop() {

  // check for incoming serial data:

  if (Serial.available() > 0) {

    // read incoming serial data:

    char inChar = Serial.read();

    // Type the next ASCII value from what you received:

    Keyboard.write(inChar + 1);

  }
}