Author Topic: Advanced dual-role keys  (Read 2417 times)

0 Members and 1 Guest are viewing this topic.

Offline canyon

  • Thread Starter
  • Posts: 5
Advanced dual-role keys
« on: Wed, 11 March 2015, 09:39:32 »
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. Attempt

How 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. Attempt

The 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 Program

To 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/KeyFun

Since 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/044ff8120ff69317e97fedf80d104f25

What do you think? I'm really looking forward to your feedback.

So far,
canyon

Offline jorgenslee

  • Posts: 369
  • Location: Philippines
Re: Advanced dual-role keys
« Reply #1 on: Wed, 11 March 2015, 10:21:01 »
I think your idea is related to this https://geekhack.org/index.php?topic=51069.0

Also TMK firmware supports this dual-role keys. You should check it out.

Offline canyon

  • Thread Starter
  • Posts: 5
Re: Advanced dual-role keys
« Reply #2 on: Wed, 11 March 2015, 11:57:36 »
i don't know why i didn't find that thread(s), but you're right, it's basically the same idea...

so the only thing that remains new is the (experimental) implementation of a keyboard remapping program in python (for windows). This implementation lets you create multi-layer layouts in very short time and could be really helpful for those who just want to try something out. you can define different dual-role keys that lead to different layers of the layout.

Another point is that this tool is able to work with mouse buttons in addition to keyboard buttons. This could be useful to change the keyboard layer while one hand rests on the mouse and the other hand is typing on the keyboard.


Offline suicidal_orange

  • * Global Moderator
  • Posts: 4771
  • Location: England
Re: Advanced dual-role keys
« Reply #3 on: Wed, 11 March 2015, 14:21:10 »
The python config thing has been done too - see Easy AVR which has "tap key" mode for modifiers which does what you asked about first :)
120/100g linear Zealio R1  
GMK Hyperfuse
'Split everything' perfection  
MX Clear
SA Hack'd by Geeks     
EasyAVR mod

Offline jacobolus

  • Posts: 3661
  • Location: San Francisco, CA
Re: Advanced dual-role keys
« Reply #4 on: Wed, 11 March 2015, 14:25:44 »
The ideal is really to handle this in the keyboard firmware. Gives you much more control than trying to handle it in software on the computer side.

I recommend checking out hasu’s tmk_keyboard firmware.

Offline Findecanor

  • Posts: 5036
  • Location: Koriko
Re: Advanced dual-role keys
« Reply #5 on: Wed, 11 March 2015, 15:47:19 »
Edgar Matias, of Matias keyboards once co-wrote a research paper about dual-role modifiers. The research manifested itself in the Matias Half-Keyboard. The paper is last in this post.

Hosts don't differentiate between cases (2) and (3) in your figure. The OS needs to know at the point when key B is pressed if modifier A is held down or not.

Matias and Hasu's TMK firmware instead use a timeout: If the key press is no longer than about 1/4 second then it is a tap, otherwise it is a hold.