Page 1 of 1

HID Keyboard Report out from python (e.g. CAPS LOCK Status)

Posted: Tue Jul 09, 2019 7:49 pm
by seemefirst@gamil.com
Hello,
Just wondering if there is any method to get HID keyboard report out byte in python code.

Reason for asking:
when a py board connected to a host computer and acts as a HID keyboard if you have another keyboard connected to the same host and press "CAPS LOCK" then capitalization on the characters you send out from pyboard will change. For example if you intend to send 'A' you will receive 'a' and vise versa.

Also HID keyboard report out could be used to check the status of "SCROLL LOCK" and "TAB" which add many useful functionalities to switch between USB modes without the user button. Users can store the last mode in a non volatile memory and switch it by pressing any of keys available in report out byte.

Looking forward to have your input.

Re: HID Keyboard Report out from python (e.g. CAPS LOCK Status)

Posted: Wed Jul 10, 2019 11:17 am
by jimmo
Using the recv method on the USB_HID class.

Code: Select all

import pyb
kb = pyb.USB_HID()

buf = bytearray(1)
while True:
    if kb.recv(buf, timeout=20) > 0:
        print(buf)
I don't have a capslock key on my real keyboard but I tested this using `xdotool key Caps_Lock` and I saw the capslock status being reported on a Pyboard using the above code.

Re: HID Keyboard Report out from python (e.g. CAPS LOCK Status)

Posted: Wed Jul 10, 2019 4:00 pm
by seemefirst@gamil.com
Thanks Jimmo,