|
|
View previous topic :: View next topic |
Author |
Message |
spilz
Joined: 30 Jan 2012 Posts: 219
|
USB Keyboard : how to find scancode for specific functions ? |
Posted: Sun Jul 28, 2024 5:37 pm |
|
|
Hello everyone
i'm working on a project with a PIC18F2550 to use it as an USB keyboard.
I'm able to send ASCII properly, I'm able to send scancode from this list properly :
Code: | typedef enum
{
USB_KBD_SCANCODE_ESC = 0x29,
USB_KBD_SCANCODE_CAPS_LOC = 0x39,
USB_KBD_SCANCODE_F1 = 0x3A, //F2 is 0x3B, F3 is 0x3C, etc. this is valid up to F12
USB_KBD_SCANCODE_PRTSC = 0x46,
USB_KBD_SCANCODE_SCROLL_LOCK = 0x47,
USB_KBD_SCANCODE_PAUSE = 0x48,
USB_KBD_SCANCODE_INS = 0x49,
USB_KBD_SCANCODE_HOME = 0x4A,
USB_KBD_SCANCODE_PG_UP = 0x4B,
USB_KBD_SCANCODE_DEL = 0x4C,
USB_KBD_SCANCODE_END = 0x4D,
USB_KBD_SCANCODE_PG_DN = 0x4E,
USB_KBD_SCANCODE_RIGHT = 0x4F,
USB_KBD_SCANCODE_LEFT = 0x50,
USB_KBD_SCANCODE_DOWN = 0x51,
USB_KBD_SCANCODE_UP = 0x52,
USB_KBD_SCANCODE_NUM_LOCK = 0x53,
USB_KBD_SCANCODE_WIN_MENU = 0x65,
USB_KBD_SCANCODE_F13 = 0x68, //F14 is 0x69, F15 is 0x6A, etc. this is valid up to F24
USB_KBD_SCANCODE_HELP = 0x75,
USB_KBD_SCANCODE_UNDO = 0x7A,
USB_KBD_SCANCODE_CUT = 0x7B,
USB_KBD_SCANCODE_COPY = 0x7C,
USB_KBD_SCANCODE_PASTE = 0x7D,
USB_KBD_SCANCODE_MUTE = 0x7F,
USB_KBD_SCANCODE_VOL_UP = 0x80,
USB_KBD_SCANCODE_VOL_DOWN = 0x81
} kb_scancode_t;
|
but I need to use more "special" keys as the ones which are on the F1 F2 ... keys (back, musique, next, previous, play, etc.)
but I don't find how to use them.
more global, I don't understand where come from this kb_scancode_t values.
I tried to compare with this :
https://www.plantation-productions.com/Webster/www.artofasm.com/DOS/pdf/apndxc.pdf
but for example ESC = 0x01 and USB_KBD_SCANCODE_ESC = 0x29
thanks in advance for your help |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Jul 29, 2024 1:06 am |
|
|
This is one of those lovely complicated things.
Now start with the table you have found. This gives PS/2 scancodes. These
were the codes a keyboard device actually sent when connected to the old
PS/2 connector. Now these were interpreted internally inside the PC, so
pressing the ESC key gave a 1, and releasing it gave an 0x81. The internal
code in the PC, then translated this into the ESC being pressed and released
operations.
When USB launched, they decided to implement loads more possibilities than
the basic codes, so the handling moved away from these codes. Instead
you have a huge list of codes for the keys, and the operations on these
(some of which are latched, and some happen only when the corresponding
key is pressed), and the scancodes remain the same for the key involved.
So (for example), '?', returns the same key number as '/', but with
the shift set.
Now to make things worse, different keyboard manufacturers change where
things actually are on the keyboard.
Key list to pull is:
[url]
https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf&ved=2ahUKEwiv9o6UzsuHAxWWX0EAHQa5NQIQFnoECCYQAQ&usg=AOvVaw0qYepWO28gAp8NbbWWs5EY
[/url]
This lists every key Microsoft admit to, and their USB scancodes, together
with the PS/2press and release codes.
Now, some of the ones you are asking about are complex, since they are
not actually standard HID keyboard codes. They use usage pages other
than 7. This is because they are not actually functions originally assigned
to the 'keyboard'. 0xC is actually a 'consumer page' ID. So a character
coming from a special controller, not a keyboard. If you really need to
send these, you are actually going to have to implement another device
using this usage page, with it's own USB descriptor for this page. You
can potentially do this with a combined USB descriptor (look at the
example for kbmouse), so the driver effectively generates two USB
devices, one a keyboard, and the second (for your case), a consumer
controller.
Look at this thread about this:
[url]
https://stackoverflow.com/questions/55166120/combine-keyboard-consumer-control-in-descriptor
[/url]
In particular the last post here.
Do a search on 'USB composite device', for a lot about this. |
|
|
spilz
Joined: 30 Jan 2012 Posts: 219
|
|
Posted: Mon Jul 29, 2024 2:22 am |
|
|
Thanks a lot for you explanations
I’m going to try to do it the way you suggest
Have a good day |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Wed Jul 31, 2024 1:29 am |
|
|
Good stuff.
Key point here is that he still needs to handle the composite device part,
since he wants both a keyboard and a multimedia controller, but this gives
most of the stuff for the latter. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|