Discussion:
backspace and delete key mappings
(too old to reply)
d***@cfl.rr.com
2006-03-31 15:09:40 UTC
Permalink
I have read much on the subject of these 2 keys. Yet I have not been
able to do what I need to do. I need the backspace key to generate
0x08(^H) and the delete key to generate 0x7f(del) during the execution
of a single application. On all my linux boxes the backspace generates
0x7f(^?) and the del key generates ^[[3~. I need to be able to change
that before I execute my program then change it back when my
application is done. stty does NOT do the job nor does my application
use termdef. I have found a little expect script that does do what I
need. I execute "script program" and the keys come out like I want.

#!/usr/bin/expect

eval spawn -noecho $argv

interact {
\177 {send "\010"}
"\033\[3~" {send "\177"}

However I am really looking for basic Linux commands that can be
executed from the bash shell that will do the same thing or a method of
making my application do it from within its self.

Thanks and regards
Mark
Michael Paoli
2006-04-01 00:01:44 UTC
Permalink
Post by d***@cfl.rr.com
I have read much on the subject of these 2 keys. Yet I have not been
able to do what I need to do. I need the backspace key to generate
0x08(^H) and the delete key to generate 0x7f(del) during the execution
of a single application. On all my linux boxes the backspace generates
0x7f(^?) and the del key generates ^[[3~. I need to be able to change
that before I execute my program then change it back when my
application is done. stty does NOT do the job nor does my application
use termdef. I have found a little expect script that does do what I
need. I execute "script program" and the keys come out like I want.
#!/usr/bin/expect
eval spawn -noecho $argv
interact {
\177 {send "\010"}
"\033\[3~" {send "\177"}
However I am really looking for basic Linux commands that can be
executed from the bash shell that will do the same thing or a method of
making my application do it from within its self.
Ah, ... entire "religious wars" can be started over what those keys
"should" generate, and what the UNIX erase, kill, and interrupt
characters should be. Fortunately these can be changed at system-wide
default levels (at least for the most part), or per user/session, or
even within application(s).

You do mention LINUX, but you didn't mention what architecture and
distribution/version. Some of this can vary significantly depending
on hardware. E.g. on PA-RISC, x86 ("AT", "PS/2", or "USB"), SPARC,
etc. hardware, the "answers" may be rather significantly different.

You also don't mention if this is under X11, or not, and if under X11,
if any particular terminal emulation (e.g. xterm(1)) is being used.

I'll provide some hopefully useful hints/pointers. These may not
cover 100% of what you're after, but hopefully provide at least useful
starting points and information on areas to investigate further.

First there's the console keyboard itself. For typical x86 hardware
under LINUX (peeking at my Debian GNU/Linux 3.1 system - note that I
also don't strictly adhere to Debian Keyboard Policy[1]), here's at
least part of what I have in my /etc/init.d/local-keymap.sh:
echo '

keymaps 0-2,4-6,8-9,12

#make the Backspace key generate BackSpace
keycode 14 = BackSpace

#make control-shift-/ i.e. control-? generate Delete
shift control keycode 53 = Delete

#make the Delete key generate Delete
keycode 111 = Delete

' |
/bin/loadkeys

Then there are matters such as X11. My ~/.Xdefaults includes, at
least in part:
XTerm*ttyModes: erase ^H
*VT100.Translations: #override ~Meta <Key>Home: string("\033OH")\n\
<Key>End: string("\033OF")

Footnotes/references:
1. http://www.debian.org/doc/debian-policy/ch-opersys.html#s9.8
stty(1)
loadkeys(1)
dumpkeys(1)
showkey(1) http://debaday.livejournal.com/28774.html
xmodmap(1)
xkeycaps(1)
xterm(1)
xev(1)
apropos keyboard | fgrep -v '(3'
LSB: http://www.linuxbase.org/
d***@cfl.rr.com
2006-04-01 08:54:07 UTC
Permalink
Thanks. These are generally SuSE-9 and 10 boxes. X86 and X86-64. As I
said I have read much on this subject and have read about all these
things. The first method is global so I can't use that. The Xdefaults
method won't work because the program is "mostly" being executed from a
normal linux console without X. stty just does not do the job. "stty
erase "^h" doesn't change what the backspace key generates anymore and
does not help with the del key.

I thought I could just create a termcap or terminfo entry for a
"custom" terminal type. Then just setterm -term custom. This does not
seem to work either. It almost seems like the termcap and terminfo
stuff is just there for "looks" and actually does nothing these days.

You mention "from within applications"???

Thanks
Mark
Chuck Dillon
2006-04-10 14:34:36 UTC
Permalink
Post by d***@cfl.rr.com
Thanks. These are generally SuSE-9 and 10 boxes. X86 and X86-64. As I
said I have read much on this subject and have read about all these
things. The first method is global so I can't use that. The Xdefaults
method won't work because the program is "mostly" being executed from a
normal linux console without X. stty just does not do the job. "stty
erase "^h" doesn't change what the backspace key generates anymore and
does not help with the del key.
If you do... (stty erase ^h;yourapp) your app should see the affect.
Is this not working?

You need to find separate solutions for the console case versus the X
case. Stty should provide a solution to the console case. X resource
settings and stty should enable you to deal with the X case.

-- ced
Post by d***@cfl.rr.com
I thought I could just create a termcap or terminfo entry for a
"custom" terminal type. Then just setterm -term custom. This does not
seem to work either. It almost seems like the termcap and terminfo
stuff is just there for "looks" and actually does nothing these days.
You mention "from within applications"???
Thanks
Mark
--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
d***@cfl.rr.com
2006-04-01 10:27:33 UTC
Permalink
I forgot to mention that when I do run the app under X and kde's
konsole, and change the terminal type to konsoles' internal vt420pc
emulation all is fine and the 2 keys are what I need them 2 be. I
wonder how konsole is doing it?

Mark
d***@cfl.rr.com
2006-04-07 11:04:28 UTC
Permalink
Surely this must be possible. Can no one help me?

Thanks
Mark
Michael Paoli
2006-04-11 09:41:56 UTC
Permalink
Post by d***@cfl.rr.com
I forgot to mention that when I do run the app under X and kde's
konsole, and change the terminal type to konsoles' internal vt420pc
emulation all is fine and the 2 keys are what I need them 2 be. I
wonder how konsole is doing it?
Use the source, Luke. Seriously, you're talking about Open Source
software. Read/research the source code and/or applicable
documentation as necessary. There are answers there to be found.
Surely if X11 clients and showkey(1) can map keys as you desire and/or
grab key codes before they're translated into characters, it certainly
can be done. The xkeycaps(1) man page also covers a fair bit of
information about ... "S.u.S.E. ship their systems with broken
keyboard settings by default" ... but perhaps that portion of the
xkeycaps(1) man page isn't included in the SuSE distribution.

And other semi-related random tidbit, I recently also added this to my
~/.Xdefaults file:
*backarrowKeyIsErase: false

Also, learn to include at least minimal relevant quoting for context,
otherwise in many cases someone will see your posting and have no idea
what you're talking about, e.g. your: news:***@u72g2000cwu.googlegroups.com
provides essentially no relevant context.
See:
http://cfaj.freeshell.org/google/
etc.

references: news:***@j33g2000cwa.googlegroups.com news:***@t31g2000cwb.googlegroups.com news:***@i39g2000cwa.googlegroups.com
strace(1)
gdb(1)
etc.

Jordan Abel
2006-04-01 00:49:36 UTC
Permalink
Post by d***@cfl.rr.com
I have read much on the subject of these 2 keys. Yet I have not been
able to do what I need to do. I need the backspace key to generate
0x08(^H) and the delete key to generate 0x7f(del) during the execution
of a single application. On all my linux boxes the backspace generates
0x7f(^?) and the del key generates ^[[3~. I need to be able to change
that before I execute my program then change it back when my
application is done.
Why do you need bs=^H del=^? - that seems like a poor assumption to make
on the part of your application. what application is this?
d***@cfl.rr.com
2006-04-01 09:02:59 UTC
Permalink
The application is an emulation of a leagacy computer that had an rs232
port for it's console usually with a dumb terminal connected. Every
dumb terminal ever connected to it sent ^h for backspace and ^? for
delete. Perhaps it was a poor assumption, on the part of the developers
of that platform (of which I played a very small part), that there
could ever be such a fuss over these 2 keys in the future.
Loading...