[ale] Slightly OT: Coding program to hit several keys at once
Scott Plante
splante at insightsys.com
Tue Dec 5 16:03:59 EST 2017
You can probably do it in a lot of languages. You can do it in Java by listening to KeyListener events. You get an event each time a particular key is depressed and released, in addition to a higher level event for a key "typed".
from: https://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html
<blockquote>
Type an uppercase 'A' by pressing the Shift and A keys.
</blockquote>
<blockquote>
You'll see the following events, although perhaps not in this order: key-pressed (Shift), key-pressed (A), key typed ('A'), key-released (A), key-released (Shift). Note that Shift is listed as the modifier key for the key-typed and key-pressed events.
</blockquote>
You would need to keep track of your key-pressed and key-released events to see what the complete combination was. Maybe something like this pseudo-code:
List currentKeys = new List()
List comboKeys = new List()
while true()
{
keyPressed(KeyEvent e) {
currentKeys.add(e.getKeyChar());
comboKeys.add(e.getKeyChar());
}
keyReleased(Keyevent e) {
currentKeys.remove(e.getKeyChar())
if (currentKeys.size()==0) // end of sequence
{
char c = comboMap.get(comboKeys.sort());
if (c != null)
typeCharacterInEditor(c);
comboKeys.removeAll();
}
}
Each time you depress a key it gets added to 2 lists. When you release it gets removed from the currently depressed list. Once all keys are released, you look at the list of all that were depressed during the current cycle and see if it matches one of your valid combinations. If so, you consider the matched character "typed". Either way you clear your second list for the next round.
--
Scott Plante
404-873-0058 x104
----- Original Message -----
From: "Todor Fassl via Ale" <ale at ale.org>
To: "Atlanta Linux Enthusiasts" <ale at ale.org>
Sent: Tuesday, December 5, 2017 11:22:28 AM
Subject: [ale] Slightly OT: Coding program to hit several keys at once
I want to write some code to simulate a braille keyboard. A braille
keyboard has 7 keys. One is the space bar. The other 6 you press at the
same time in different combinations. So, for example, on a braille
keyboard, to make the letter x, you press the 1, 3, 4, and 6 keys at
once. I want to simulate that by allowing the user to press the f, s, j,
and l keys at the same time. Does anybody know of a programming language
that handles something like that nicely? If you were going to recommend
a programming language to do that, what would it be?
My goal is to write a text editor that allows a user to type braille and
saves the output in BRF format. So the user hits the f, s, j, and l keys
at once and the editor puts a BRF character x into the buffer.
Right now, I'm leaning toward python because python has a gaming library
that seems to allow you to hit several keys at once. But maybe somebody
has done something like this in C or C++. I am about as sure as I can be
that perl won't work. I don't particularly care about the programming
language because by now I've learned so many different programming
languages in my life I figure I can learn another one in a few
days/weeks. I don't actually care if the code is portable to other
operating systems other than linux. That might be nice but it's not
important.
--
Todd
_______________________________________________
Ale mailing list
Ale at ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20171205/535cf5f8/attachment.html>
More information about the Ale
mailing list