Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: How can I convert a string of "KEY_A" to the Keyboard.h KEY_A define value?

  1. #1

    How can I convert a string of "KEY_A" to the Keyboard.h KEY_A define value?

    I'm building a project that accepts commands over RS232 and then sends a keystroke over USB HID using the Teensy 3.2.

    What is the most efficient way to accept any keystroke string and then convert it to the correct value for Keyboard.press() ?

    Thanks for any help!

  2. #2
    Junior Member
    Join Date
    Jul 2016
    Posts
    4
    If you do it that way, you pretty much have to create some sort of lookup table in your program and search it.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,734
    Use Keyboard.print(char). It knows how to translate characters to the actual keystoke, based on the keyboard layout you selected in Tools > Keyboard Layout.

    Code:
    if (Serial.available()) {
      char c = Serial.read();
      Keyboard.print(c);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •