Hi,
tl;dr: Single key can be used as a normal key or as a modifier. Depending on the order of key presses/releases, a program determines if the keystroke of a key was intended to be a normal key or a modifier.
A key can be pressed / not pressed. To illustrate my ideas, i created some pictures which show the pressed state of some keys over time.
1. AttemptHow to decide whether a key X was used as a normal key or as a modifier:
1. If no other keys were released between the press and release of the key X, it was used as a normal key.
2. If all other keys that have been released between the press and release of key X were pressed before X was pressed, X was used as a modifier. (Assume key X is key B in example 2)
3. If a key has been pressed after key X had been pressed and is released, before key X is released, X is used as a modifier. (See example 3, key X is key A)
Using this logic, a key can act as a normal key AND as a modifier key. Example:
Imagine a normal keyboard layout. Now we just modify the space key to be the SPACE key as normal key and the SHIFT key as a modifier.
You can type normally using the SPACE key to produce spaces, and if you want to type capital letters, simply hold the SPACE key and type the keys you want to write in capital.
Problems/Properties:
- Normally, the space character is typed when the space key is pressed. Since it is not clear whether the key is used to type a space character or hold the shift key, the appropriate action can not be performed when the key is pressed. This leads to a noticeable input delay.
- Such keys can not be repeated by holding them. The reason for this is the same as for the input delay.
- When releasing the key which should be used as a modifier too soon (which happens more often than i thought), the key is used as a normal key and the combination doesn't work.
2. AttemptThe second attempt extends the first attempt by another rule to decide whether a key is used as a normal key or as a modifier:
4. When a key is pressed longer than a specific threshold, it is used as a modifier.
This solves the last of the Problems mentioned above. Whenever you type a combination of keys, you hold the modifier key longer than you would if it was just a normal key. If the threshold is set appropriate, it can distinguish between these two types of key presses.
Another advantage is the input delay, which now is limited by the specified threshold.
I'm not sure if my explanations were understandable, but i hope so. If you've got any questions, feel free to ask them.
Prototype ProgramTo test this concept, i wrote a program in python. It's a prototype and i can't guarantee that it is bug-free, but if you want, you can play with the source code that is hosted on Github:
https://github.com/caenyon/KeyFunSince Keyboard input is heavily platform dependent, the program only works on Windows and needs some additional python packages. PyHook is one of these packages, but there may be more to install. I'm running it on Python 2.7 and don't know if it also works with Python 3.
Run test.py to start the program. This is also the place to edit the layout. I think that most of the code in test.py is easy to understand and to modify. A key with the function mentioned above is called complex_key in the program. There are also simple_keys and simple_modifiers. The latter switch between program internal layers.
I implemented a simple layout that is based on the normal layout. The SPACE key is a complex_key and switches to the second layer containing numbers and other symbols. This second layer looks like this:
http://www.keyboard-layout-editor.com/#/layouts/044ff8120ff69317e97fedf80d104f25What do you think? I'm really looking forward to your feedback.
So far,
canyon