rust-embedded-community / pc-keyboard

PS/2 Keyboard Decoder in Rust
Apache License 2.0
96 stars 28 forks source link

Inconsistent decoding #4

Open rybot666 opened 5 years ago

rybot666 commented 5 years ago

Your crate decodes some keys into DecodedKey::RawKey objects. Theenum that you provide containing keys has a Backspace variant, but, using QEmu as my example, a backspace is decoded into unicode U+0008, and as a DecodedKey::Unicode.

thejpster commented 5 years ago

That's because I understood 0x08 to be the ASCII value for Backspace, like 0x09 is the ASCII value for Tab. I only used DecodedKey::RawKey when there wasn't a clear mapping to an ASCII (or Unicode) value (e.g. there's no ASCII or even Unicode value corresponding to the Windows key). If you'd rather have raw key events (i.e. the KeyCode enum you mention that includes KeyCode::Backspace, plus an indication of whether the key was pressed or released), you can avoid calling process_keyevent and handle the key events yourself.

rybot666 commented 5 years ago

Then can we remove the Backspace variant of the enum, as it is not used, and only use ASCII Backspace

thejpster commented 5 years ago

It is used if you take KeyEvents and don't decode them.

I can see your point though. I could create a new enum called UndecodableKeys or something. It would include Home, PageUp, etc, but not A, +, or Backspace. You can then match exhaustively without overlaps.