geekhack
geekhack Projects => Making Stuff Together! => Topic started by: wolfv on Tue, 17 December 2013, 00:04:20
-
Normally Shift characters like ~!@#$%^&()_{}<> are activated with the shift key.
Some keyboard software can activate Shift characters via layer key e.g. ErgoDox.
I am writing a keyboard program for Teensy that activates Shift characters via layer key.
Does anyone know how Shifted characters are implemented in ErgoDox or any keyboard software?
I would greatly appreciate it if you could point me to an open source file where Shifted characters are implemented.
Thank you.
-
i am not a firmware dev so i may not be the best one to explain this, but from my understanding, the shifted characters are implemented at the OS level. you might be thinking of the function layers, which are implemented at the keyboard firmware level.
-
You could check out the ergodox firmware. https://github.com/benblazak/ergodox-firmware
-
Hi sth,
That's true. Somehow the keyboard key is sending a shift code + key code to the OS.
The following lines are coped from arduino-1.0.5\hardware\teensy\cores\teensy\keylayouts.c:
#define SHIFT_MASK 0x0040
...
#define ASCII_2D KEY_MINUS // 45 -
...
#define ASCII_5F KEY_MINUS + SHIFT_MASK // 95 _
For example, there is probably a way to use the ASCII_5F macro to implement the underscore character, but I don't see how to do it.
-
You could check out the ergodox firmware. https://github.com/benblazak/ergodox-firmware
Hi nuclearsandwich,
I briefly looked at the ergodox firmware and released figuring out where the Shift characters are implemented will take much time. I am hoping that someone familiar with the firmware can point me to the relevant file.
-
Hi wolfv,
I'm going to assume that the keyboard handles this, and without thinking too hard about the best way it would do it, I'll just throw out some human-readable pseudo code:
// (inside some kind of input checking loop or function)
if function_layer_key then
...
if key_you_press then
send( shift_key_press)
send( whatever_key_press)
end
...
end
Basically, my feeling is that while the keyboard (teensy in your case) is scanning the matrix to see what is being pressed, it does a compare against the function layer key, and if that is pressed, it just sends a different (or combination of) key press signal(s) to the computer.
-
Hi Neebio,
I was thinking the same thing. Here is the preliminary code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//macros copied from arduino-1.0.5\hardware\teensy\cores\teensy\keylayouts.c
#define MODIFIERKEY_SHIFT ( 0x02 | 0x8000 )
#define KEY_MINUS ( 45 | 0x4000 )
#define SHIFT_MASK 0x0040
#define ASCII_5F KEY_MINUS + SHIFT_MASK // 95 _
int main()
{
int key = ASCII_5F; // the underscore key from layout
if (key & SHIFT_MASK == SHIFT_MASK)
{
cout << "send(MODIFIERKEY_SHIFT)" << endl;
cout << "send(" << key - SHIFT_MASK << ")" << endl;
cout << " " << KEY_MINUS; // should be equal to key - SHIFT_MASK
}
}
output:
send(MODIFIERKEY_SHIFT)
send(16429)
16429
-
i am not a firmware dev so i may not be the best one to explain this, but from my understanding, the shifted characters are implemented at the OS level.
Even worse, the selected keyboard layout in the OS has to be also considered, as for example some keycodes and symbols on the shift/altgr "layers" are different. That's why i chose to store each modifier necessary together with each character to be able to switch languages and also put keys needing different modifiers on one layer in my Keyboard firmware. Essentially, this conpletely decouples the keycode matrix from any layer modifiers, which I think neither tmk nor the Ergodox fw caters for. But with macros you could work around that limitation, too
-
store each modifier necessary together with each character to be able to switch languages and also put keys needing different modifiers on one layer in my Keyboard firmware. Essentially, this completely decouples the keycode matrix from any layer modifiers
Thanks suka.
After poking around the USB standards I came to the same conclusion. What a mess. It would have been nice if only letters were coupled to shift.
I am in the process of writing a wrapper class called "ScanCodes" that decouples keycodes from keyboard position.