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

Status
Not open for further replies.

trackoid

New member
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:
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?
 
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
 
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.
 
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.
 
Status
Not open for further replies.
Back
Top