Skip to content

Keyboard and Mouse not working from 1.8.0 release on #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
per1234 opened this issue Jun 26, 2019 · 14 comments
Open

Keyboard and Mouse not working from 1.8.0 release on #423

per1234 opened this issue Jun 26, 2019 · 14 comments
Assignees

Comments

@per1234
Copy link
Contributor

per1234 commented Jun 26, 2019

Describe the problem

When using version 1.8.0 or higher of the platform, there are problems with HID functionality of the boards:

  • Mouse emulation doesn't work at all on Windows machines
  • Keyboard emulation doesn't work at all on Windows machines
  • Keyboard emulation is incorrect on Linux machines

To reproduce

Equipment

  • Any of the boards supported by the platform.

Steps

Keyboard
  1. Upload the following sketch to one of the platform's boards:
    #include <Keyboard.h>
    void setup() {
      pinMode(2, INPUT_PULLUP);
      pinMode(LED_BUILTIN, OUTPUT);
      Keyboard.begin();
    }
    
    void loop() {
      if (digitalRead(2) == LOW) {
        Keyboard.print("hello");
        digitalWrite(LED_BUILTIN, HIGH);
        delay(500);
        digitalWrite(LED_BUILTIN, LOW);
        delay(500);
      }
    }
  2. Open any text editor program, and give focus to the editor.
  3. Connect pin 2 to ground.

🐛 If connected to a Windows machine, no text is typed.

🐛 If connected to a Linux machine, incorrect text is typed. For example:

heloooooooooooohelohelohelooooooooooooheloooooooooooohelheloheloooooooooooohelooooooooooooheloooooooooooohhelooooooooooooheloooooooooooohelooooooooooooheloooooooooooohelheloooooooooooohelohhelohelhhhelhelohhe
Mouse
  1. Upload the following sketch to one of the platform's boards:
    #include <Mouse.h>
    void setup() {
      pinMode(2, INPUT_PULLUP);
      pinMode(LED_BUILTIN, OUTPUT);
      Mouse.begin();
    }
    
    void loop() {
      if (digitalRead(2) == LOW) {
        Mouse.move(0, 200);
        digitalWrite(LED_BUILTIN, HIGH);
        delay(1000);
        Mouse.move(0, -200);
        digitalWrite(LED_BUILTIN, LOW);
        delay(1000);
      }
    }
  2. Connect the board to a Windows machine.
  3. Connect pin 2 to ground.

🐛 The mouse pointer does not move.

Has no effect on Windows, but seems to work correctly on Linux.

Arduino SAMD Boards (32-bits ARM Cortex-M0+) version

Operating system

  • Linux
  • Windows

Operating system version

  • Raspbian 9.4
  • Ubuntu 19.04
  • Windows 10 64 bit

Additional context

When compiled with version 1.6.28 or 1.6.21 of the platform, both sketches work as expected on Windows and Linux.


Reproduced using library versions:


Reproduced with the following boards:

  • MKR 1000 WiFi
  • MKR Fox 1200
  • MKR GSM 1400

Mouse emulation seems to work correctly on a Linux machine.

Additional reports

Related

@facchinm
Copy link
Member

I think the problems on Windows could be due to CDC Serial becoming pluggable, so the descriptor could be "reversed". About the keyboard bug I'll investigate later today. Same for Windows of course

@facchinm facchinm self-assigned this Jun 26, 2019
@facchinm
Copy link
Member

I found the culprit as commit a8d208a. Reverting looks safe but I want to investigate a bit more.

@facchinm
Copy link
Member

The problems in windows are 2 (related):

  • Arduino drivers only specify the CDC as first interface; forcing USB input device as target driver just works. The workaround only applies to Windows10 since previous versions has no CDC generic driver.
  • Everything is fine if SerialUSB is the first interface. Unfortunately there's no way to tell the compiler about the instantiation order of pluggable devices.
    A new API could be added to force a pluggable module to be the first (or the last).

@facchinm facchinm reopened this Jul 8, 2019
facchinm added a commit to facchinm/ArduinoCore-samd that referenced this issue Jul 8, 2019
@pedroslopez
Copy link

any update on this?

@facchinm
Copy link
Member

@pedroslopez are you still experiencing the issue? The main bug should be fixed on latest samd core, but the driver installation is still flawed (on win7)

@pedroslopez
Copy link

Yeah, it doesn't seem to be working for me. I'm running a test with the following code:

#include <Keyboard.h>

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Keyboard.begin();
}

void loop() {
  delay(5000);
  Keyboard.print("hello");
  
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);

}

I just took the code from the first post of this issue and removed the button. The keyboard is not writing anything. I'm using Arduino 1.8.12, Windows 10 64 bit, keyboard library 1.0.2 with an MKR1000.

@facchinm
Copy link
Member

Ok, so your problem is likely related with drivers installation; a solution is to open Device Manager and uninstall the MKR1000 drivers; after reset, both serial and HID (keyboard) drivers should be automatically installed (thanks to windows 10). The same procedure unfortunately doesn't work on WIn7 because the serial drivers are not included in the operating system.
Let me know if it works!

@Workshopshed
Copy link

Workshopshed commented May 24, 2020

I also have problems with the keyboard not working on the Arduino MKR Zero board on Windows 10 64bit. Looking at the drivers in USBDeview, it does look like the HID device has been assigned the serial USB driver?
This is with version 1.8.5

ArduinoHID

@Workshopshed
Copy link

Swapping back to 1.6.21 fixes the issue and the HID device is hooked up correctly.

image

image

@facchinm
Copy link
Member

Hi @Workshopshed,
when you compile the sketch with core 1.8.x the order of descriptors get reversed, so on Windows 10 (and only there) you must uninstall the drivers shipped by us for the system to correctly installs both the HID and the CDC builtin drivers. On Win7 the problem is still alive so I'm not closing the issue (and not amending the installation package either)

@Workshopshed
Copy link

Workshopshed commented May 25, 2020

So to clarify, there's no upgrade path from 1.6 to 1.8 that would correctly configure the drivers on Windows 10 and we need to work out which drivers uninstall and use a 3rd party tool to remove those?
I am happy to write the instructions if this is the case.

Or am I missing something?

@facchinm
Copy link
Member

No 3rd party software should be needed (just Win device manager) but if you write an howto it would surely be useful. @per1234 @SimonePDA do we already have an howto somewhere in the website?

The problem with our windows drivers is that they need the CDC descriptor to be the first and they replace the OS driver every time you install an 1.6.x version of the core. So, the first time you recompile on 1.8.x the cached driver will be loaded instead than the HID one. So yes, no clean upgrade path is possible unfortunately 🙁

turmary pushed a commit to Seeed-Studio/ArduinoCore-samd that referenced this issue Jun 23, 2020
This reverts commit a8d208a.

Fixes arduino#423 on Linux/Mac (and Windows when Arduino standard drivers are uninstalled)

Fix for normal behaviour on Windows is ongoing
@akshaygugnani15
Copy link

You know what you don't require the keyboard.h or 32u4 based Arduino now, I got a solution to use the keyboard and mouse through any Arduino yes you read it right any!

All you have to do is something like this:-

Serial.println("pressA")
on the Arduino

And now head to a python script and do this:-

import serial
import pyautogui
Arduino_Serial = serial.Serial('COM5', 9600)

while 1:
    incoming_data = str(Arduino_Serial.readline())
    print(incoming_data)
    if 'pressA' in incoming_data:
        pyautogui.press('a')
    incoming_data = ""

BOOM YOU ARE DONE

@goofyseeker311
Copy link

goofyseeker311 commented Feb 27, 2025

I made an IMU mouse using an older arduino studio 2.x.x, that version worked on win11 about 1 year ago (september 7 2023), but that version stopped working in the newer win11 versions. I think its about the windows/os HID drivers, not about the code or the arduino itself.

I had the mouse.h working properly in a 2.x.x version, on win11, so its not strictly 1.8.0 onwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants