Thursday, 15 March 2012

linux - Make bash differentiate between Ctrl- and Ctrl-Shift- -



linux - Make bash differentiate between Ctrl-<letter> and Ctrl-Shift-<letter> -

i wondering whether there way of making bash send different codes key combinations include shift key? instance, (ctrl+v shows me that) ctrl+n , ctrl+shift+n interpreted same (^n). or there terminal can create difference? or can bash me modified does?

a terminal doesn't interact straight keyboard; interacts stream of bytes receives, (but not necessarily) generated keyboard. printable ascii values, there obvious correspondence between value , key (or combination) on keyboard. ascii 97 a, ascii 65 shifta, , on.

however, there 32 non-printing control characters ascii 0 ascii 31, called because intended control terminal. in order come in them, control added allow you, in combination other keys, generate these codes. simple scheme used. pressing control-x generate command code corresponding subtracting 64 x. since @ generates ascii 64, control@ generates ascii 0. same mapping holds true a through _ (consult favorite ascii reference see rest of correspondences).

however, whether or not need shift key generate ascii 64 through ascii 95 depends on keyboard. on keyboard layout, [ , ] can typed without shift key. (remember, it's uppercase-letter ascii range we're using here, not lowercase.) simplify, suspect decided shift ignored in determining keycode sent control-x. (note if reason keyboard had 2 of characters between 64 , 95 generated key/shift-key pair, terminal need define alternate mapping associated command character.)

all simply(?) explain why controlshift-x , control-x typically same. obviously, modern operating scheme can distinguish kinds of keyboard combinations. out of myriad possibilities, 256 of them can send unique values terminal; rest must duplicate 1 or more of others. useful, need configured send multiple-byte sequence terminal, typically origin ascii 27 (esc). when terminals receive byte, pause moment see if other bytes coming after. keys function keys, arrow keys, etc. have standard sequences send, terminal interprets in various ways. other keys (like controlshiftn in example) have no agreed-upon meaning, , terminal emulator must assign one. emulators should allow this, how is, obviously, program-specific.

linux bash

No comments:

Post a Comment