f



Detect ctrl+shift with termios?

Is it possible to set termios such that it distinguishes
ctrl-n from ctrl-shift-n for example? I get the same code
from both.
0
luser
12/3/2016 4:45:33 AM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (350) is leader. Post Follow

9 Replies
539 Views

Similar Articles

[PageSpeed] 44

On 03/12/2016 05:45, luser droog wrote:
> Is it possible to set termios such that it distinguishes
> ctrl-n from ctrl-shift-n for example? I get the same code
> from both.

In Ubuntu, my console program uses CTRL+SHIFT+C for copy,
which is obviously interpreted differently than CTRL+C.
(I don't know if that is a relevant situation.)

Regards.

0
Noob
12/3/2016 9:31:29 AM
luser droog , dans le message
<260e6e48-54a0-47e2-8c4d-36d6c324d269@googlegroups.com>, a �crit�:
> Is it possible to set termios such that it distinguishes
> ctrl-n from ctrl-shift-n for example?

This is handled by escape sequences, not termios, and is entirely up to
the terminal (emulator) you are using. I do not know any that provides
the feature.
0
Nicolas
12/3/2016 9:54:53 AM
In article <5842966d$0$3305$426a74cc@news.free.fr>,
 Nicolas George <nicolas$george@salle-s.org> wrote:

> luser droog , dans le message
> <260e6e48-54a0-47e2-8c4d-36d6c324d269@googlegroups.com>, a �crit�:
> > Is it possible to set termios such that it distinguishes
> > ctrl-n from ctrl-shift-n for example?
> 
> This is handled by escape sequences, not termios, and is entirely up to
> the terminal (emulator) you are using. I do not know any that provides
> the feature.

X-Windows sends key presses and releases. You can write X-Windows or Tk/Xyzzy 
code instead of using an xterm.

-- 
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted.
'I desire mercy, not sacrifice.'
Free the Amos Yee one.
Yeah, too bad about your so-called life. Ha-ha.
0
Siri
12/3/2016 1:32:20 PM
Siri Cruise , dans le message
<chine.bleu-11F160.05321403122016@news.eternal-september.org>, a �crit�:
> X-Windows sends key presses and releases. You can write X-Windows or Tk/Xyzzy 
> code instead of using an xterm.

That would require writing a complete GUI application. I hope you
realize this is several orders of magnitude more work than an
application running in a terminal.
0
Nicolas
12/3/2016 2:07:02 PM
In article <5842d186$0$4303$426a74cc@news.free.fr>,
 Nicolas George <nicolas$george@salle-s.org> wrote:

> Siri Cruise , dans le message
> <chine.bleu-11F160.05321403122016@news.eternal-september.org>, a �crit�:
> > X-Windows sends key presses and releases. You can write X-Windows or 
> > Tk/Xyzzy 
> > code instead of using an xterm.
> 
> That would require writing a complete GUI application. I hope you
> realize this is several orders of magnitude more work than an
> application running in a terminal.

Yes, I do. It's up to the coder to decide whether capturing all keystrokes is 
worth the effort. The various Tks are a simpler interface but still learning new 
strategies and tactics.

Also it's been a while since I have done raw X-Windows, but it might be possible 
to attach some of this to preferences for the xterm. That would still require 
knowing some of X.

-- 
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted.
'I desire mercy, not sacrifice.'
Free the Amos Yee one.
Yeah, too bad about your so-called life. Ha-ha.
0
Siri
12/3/2016 3:36:49 PM
On Sat, 2016-12-03, Nicolas George wrote:
> Siri Cruise , dans le message
> <chine.bleu-11F160.05321403122016@news.eternal-september.org>, a �crit�:
>> X-Windows sends key presses and releases. You can write X-Windows or Tk/Xyzzy 
>> code instead of using an xterm.
>
> That would require writing a complete GUI application. I hope you
> realize this is several orders of magnitude more work than an
> application running in a terminal.

Not to mention the poor user might not /want/ a window.  Perhaps she's
not even running X11 locally.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .
0
Jorgen
12/3/2016 4:30:36 PM
On Sat, 03 Dec 2016 09:54:53 +0000, Nicolas George wrote:

> This is handled by escape sequences, not termios, and is entirely up to
> the terminal (emulator) you are using. I do not know any that provides the
> feature.

Many X-based terminal emulators let you configure them to send specific
strings in response to specific key combinations.

E.g. xterm, being Xt-based, is controlled by the "translations" resource
on the vt100 widget. Binding a key sequence to the string(...) action
allows an arbitrary string to be sent.

But there's no generic mechanism for configuring terminal emulators (and
even less so for physical terminals).

0
Nobody
12/4/2016 10:29:41 PM
> Is it possible to set termios such that it distinguishes
> ctrl-n from ctrl-shift-n for example? I get the same code
> from both.

If you are using a terminal such as a vt-100 with its built-in
keyboard, there is no difference between those keystrokes.  You
can't provoke the terminal into telling you which was typed, not
even by threatening to pull the plug.

If you have a PC keyboard (or an emulation of one) directly connected
to the system in question, you may be able to put the keyboard
driver in a mode where it will give you scan codes (press and release
codes for each key, which is what the keyboard sends the computer),
not characters.  This mode is *NOT* part of termios.  It also means
that it's up to you to handle translating keypresses and key releases
into characters, which means you have to know the national layout
of the keyboard.  Keyboard drivers are also expected to support
several varieties of keyboard (such as 84-key vs. 104-key) which
have different scan codes sets.

The FreeBSD keyboard driver has such a feature (used by X).  It
uses ioctl(fd, KDSKBMODE, mode), where mode is one of K_XLATE (return
ASCII codes), K_CODE (returns key codes, not make-and-break), or
K_RAW (returns make-and-break scan codes).  There's also ioctl(fd,
KDGKBMODE, &mode) to find out what the current mode is, and some
others to let you control the keyboard LEDs and tell the driver the
shift state.  The header for these defines is <sys/kbio.h>.  Linux
has one also, and the symbols and header file vary a little, but
the same basic idea is there.  Actually, there are more than 2
modes, and you can select what type of translated scan codes you
get.

Getting this all to work with virtual console switching with the
virtual consoles each apparently having their own keyboard mode is
messy, and requires kernel support.  Getting it to work with your
program, X, and virtual consoles all at the same time is even harder.

I have played around with a test program that uses this mode, largely
to see what codes certain keyboards generated (sometimes the key
cap labels on laptop keyboards are outright WRONG! for keys like
Insert, Delete, Num Lock, and Scroll Lock, or maybe you want to
figure out what those "media keys" on the keyboard really do), and
it's really easy to lock yourself out of the system console if your
test program is the least bit buggy.  The program needs to put the
mode back to normal before exiting.  Also, if you have arranged
something to type that means "clean up and exit the program", it's
a real good idea to also have a certain time period (e.g. 2 minutes)
of no typing also get you out, just in case the "exit" sequence
isn't recognized properly.  It can also work to put a program in
the background that waits a while, then sets the mode back, before
running a possibly-buggy program that fiddles with the keyboard
mode.

If the program exits prematurely without putting the mode back or
aborts, you have the keyboard left in a mode where you can't type
anything on the console.  At this point the alternatives are: (1)
ssh in remotely and run the program in a mode which puts the keyboard
back to its normal operating mode, (2) ssh in remotely and reboot
the system cleanly, (2) Hard reset or power-cycle the system, with
an unclean shutdown.

If you are interested, see the FreeBSD port "misc/kbdscan".  You
invoke it, type something, and you see what scan codes are generated.
You stop typing, and eventually it exits.

If you want to pass the scan codes over a network, you probably
need to use the X keyboard protocol, or do it the hard way and
invent your own, which will require a lot of work.

0
gordonb
12/13/2016 2:36:26 AM
On Monday, December 12, 2016 at 8:36:35 PM UTC-6, Gordon Burditt wrote:
> > Is it possible to set termios such that it distinguishes
> > ctrl-n from ctrl-shift-n for example? I get the same code
> > from both.
> 
> If you are using a terminal such as a vt-100 with its built-in
> keyboard, there is no difference between those keystrokes.  You
> can't provoke the terminal into telling you which was typed, not
> even by threatening to pull the plug.
> 
<snip lower level keyboard ideas>
> If you want to pass the scan codes over a network, you probably
> need to use the X keyboard protocol, or do it the hard way and
> invent your own, which will require a lot of work.

I think I'll forgo this feature and stick to posix.
It seems that the Unicode code points leave the C1
block for the ansi terminal codes and my test setup
seems workable. Just sticking to vt100 (or maybe vt220)
codes and utf-8.

My test code is in the recent message 
"Prototype line-editor for APL interpreter".
Uncomment the lines in get_character() to dump the bytes
of all control sequences.
0
luser
12/14/2016 7:52:02 AM
Reply: