Skip to content
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

Adds the ability to output control characters #5

Merged
merged 8 commits into from
Apr 28, 2017

Conversation

dtwilliamson
Copy link
Contributor

ASCII < 0x20

Adds Keyboard.press(KEY_LEFT_CTRL), etc., to sendVal()

@Chris-Johnston
Copy link
Owner

Chris-Johnston commented Apr 26, 2017

I'm not sure if I made the whole line endings thing worse or not. Please let me know if I screwed it up. I added the .gitattributes file in 26ebf8e that should at least make things consistent. I'm just sticking with CRLF for now because that's what Visual Studio / Visual Micro likes.

@Chris-Johnston
Copy link
Owner

Chris-Johnston commented Apr 26, 2017

As for 80419a1, this raises a few issues. (In the future this might be easier to manage this in a different PR)

  • It is now impossible for users to enter any characters < 0x20, including CR, LF, escape, backspace, and tab.
  • There is no on-screen representation of printing L_CTRL + Character. (This is an easy fix)
  • The keyboard would no longer be using a standard ASCII table. Documentation should probably provide this modified table. (At that point, what if the keyboard used an entirely custom table based off of ASCII? It would be like a keymap but with 256 combinations! Could do all sorts of things with that.)

@dtwilliamson
Copy link
Contributor Author

If you enter a character < 0x20 without my change, most get changed to null by the Keyboard lib so nothing gets output to the computer. With my change, those characters get converted to their Ctrl key equivalent. (Ctrl-M is CR, Ctrl-H is backspace, etc.). The reason the Keyboard lib does this is because it functions like a USB HID keyboard. While it supports a few common keystrokes which map to keys on a keyboard, it doesn't pass others (like Ctrl-C for example). With my change, they all work. A more complex change would be to directly support the few keys that map to a keyboard and include a modified version of my change to handle the others. My change as it stands is simpler and works for all characters below 0x20.

My change does use a standard ASCII table. Ctrl characters are simply CHAR - 64 (I have to use 96 because the Keyboard lib sees the uppercase chars as shifted).

http://man7.org/linux/man-pages/man7/ascii.7.html

https://github.com/arduino-libraries/Keyboard/blob/master/src/Keyboard.cpp#L88

https://www.arduino.cc/en/Reference/KeyboardModifiers

https://en.wikipedia.org/wiki/Control_key#History (zeroing the left two bits of a seven-bit word is the same as subtracting 96)

@Chris-Johnston
Copy link
Owner

Thanks for the clear reply; I now see how this works. I think it would be worth adding a modification for Backspace, Tab, and LF, so that they still work independent of OS or environment. The other ones work fine.

@dtwilliamson
Copy link
Contributor Author

I added code to display chars below 32 on the OLED. I also implemented the HID mode and made it configurable so a user can select HID or pure ASCII handling of lower characters

@Chris-Johnston
Copy link
Owner

This is awesome. Everything works as expected, and I appreciate the the level of detail that you have put into the screen output. Thank you! I will be updating code comments and README to provide credit for your work.

@Chris-Johnston Chris-Johnston merged commit 2c8aa15 into Chris-Johnston:master Apr 28, 2017
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

Successfully merging this pull request may close these issues.

2 participants