A special key on foot

August 6, 2017

Purpose

This is clearly an inspiration from my friend @bluxte who made a usb foot keyboard for his wife.

https://bluxte.net/musings/2016/07/29/usb-foot-keyboard/

I thought about a solution to have a special key we always use as developers directly under my feet.

For now I have a fabulous Keyboard : an old IBM Model M (the original !).

If you are a specialist, you can argue that it is not an original IBM keyboard because it does not have the IBM logo on front... Except for IBM P70 or P75 keyboard because it has the logo on the other side :)

Be sure it is the best keyboard ever. Do not use it at work if you are in an openspace, it is a little noisy !

As a developer, I often use special characters such as [ and ], #, |, ` or \. All those specials characters are written with the "ALT GR" key (named "AltCar") on my keyboard. For a # you need both your two hands because the "3" key is far away from "AltGR".

The idea is to control this key using my right feet. Let see how

Note : I am a French guy. I use AZERTY keyboard this is what I use this key. For a QWERTY keyboard there is not the same problem, maybe with the SHIFT key.

Hardware

Primary, a switch for my feet. A special pedal for Pianos is very cheap. For €9.99 I got one of these

https://www.amazon.fr/dp/B01M9DYQL0/ref=pe_3044141_189395771_TE_dp_1

I also need a Teensy. It cames from the arduino family, with special functionalities such as the capability to simulate a HID keyboard. Great ! This is all I need.

Wirering

Looking at the plug :

Only 2 wires, it means that there is only a potentiometer or a simple switch

I plug those 2 wires on a 3.3V (VCC) and on a analog entry (No 23, next to VCC). A simple test with the teensy answers me : it is a simple switch.

Plug the USB port, and this part is finished !

Software

It fits in 20 lines of code. Very easy to understand.


        int lastState = 0; // 0 released, 1 pressed
        int pedalState = 0;
        void setup() {
            pinMode(23, INPUT);
            Keyboard.begin();
        }

        void loop() {
            pedalState = analogRead(23);
            if(pedalState  > 1000 && lastState == 0){
                Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
                Keyboard.send_now();
                lastState = 1;
            }
            if(pedalState  < 1000 && lastState == 1){
                Keyboard.set_modifier(0);
                Keyboard.send_now();
                lastState = 0;
            }
        }
    

"AltGR" key is equivalent to "CTRL" and "ALT". There are not common keys for the system. Sended codes are not ASCII characters representation. With the keyboard library, we set modifiers instead of "keypress".

To release modifiers, I only send "0" value

It requires a little habit and becomes very useful