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

Thread: Teensyduino 3.5 sending correct keys to computer, but incorrect keys to VM

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    3

    Teensyduino 3.5 sending correct keys to computer, but incorrect keys to VM

    I have a teensyduino that is connected to the computer as a Keyboard & Mouse.

    Teensy receives characters over the serial pin. It works flawlessly on the computer. If I send "#!A" it sends "#!A" to the laptop. However, when I launch the VM (both are windows 10) on the same computer, it receives "31a". (Notice that the # corresponds to 3 on the keyboard.)

    This makes no sense, as it is the same code and same computer essentially, but somehow the VM does not see any special characters or caps and the laptop does. What could be causing this? I checked the keyboard settings in the VM and it is set to US standard, same as the laptop itself.

    I would understand if the VM didn't receive any keys at all, but why would it receive the wrong keys?

    I am sending other commands such as "arrow up", etc and those are working fine on the VM.

    Here's the code:

    Code:
    void setup()
    {
      Serial.begin(9600);
      Keyboard.begin();
    }
    
    void loop()
    {
    
     if (Serial.available()) {
        incomingByte = Serial.read();  // will not be -1
    
        Keyboard.write(incomingByte);
    
      }
    
    }
    Last edited by trackoid; 02-06-2019 at 04:44 PM. Reason: Added more clarification

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,329
    Did you check if the VM does work correctly with the internal keyboard, or will these keystrokes also be unshifted ? Or does the VM perhaps have a different caps lock mechanism?

    I wonder why one would ask that question here, since it's obviously not a Teensy problem. If it's working outside the VM means that the Teensy is working correctly and something is weird with the VM. Just as a differential diagnose: Did you connect an external USB keyboard to the laptop and compared its behavior between the native Win10 and the virtual one? What happens in a Linux VM?

  3. #3
    Junior Member
    Join Date
    Feb 2019
    Posts
    3
    Hi - thanks for the info. Here's why I posted here:

    Keyboard.press('*'); //results in 8
    Keyboard.press(KEYPAD_ASTERIX); //results in * showing correctly

    What is the difference between a "*" and KEYPAD_ASTERIX constant? And how can I replicate that for all keys. I don't see constants for special characters such as ! % ^ & and so on.

    Thank you

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,515
    That's just the way keyboards work..

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,032
    Not sure about included examples - but a quick web search gave:

    https://www.arduino.cc/en/Reference/KeyboardPress

    and https://www.pjrc.com/teensy/td_keyboard.html

    That suggests adding " MODIFIERKEY_SHIFT " might do the trick, though neither page demonstrates that combo

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,515
    ...yes....you press *two* keys for ! % ^

  7. #7
    Junior Member
    Join Date
    Feb 2019
    Posts
    3
    Thank you gentlemen. I tried with the modifier shift key as well, but didn't work.

    I'm intrigued that it works with the KEY_ASTERIX, but not just '*'. I will pursue that avenue for other special characters.

  8. #8
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,329
    As old javascript developers know, key codes are not always identical to ASCII, since there are more and wider character sets than ASCII and since there are hundreds of different keyboard layouts. If you want to emulate a keyboard from a micro controller, you have definitively to send key codes to prevent ambiguities.

Posting Permissions

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