keyboard transmit mode in vt100 terminal emulator - terminal

I'm implementing a vt100 terminal emulator in javascript and the vt100 spec (from man terminfo and infocmp) tells me that smkx=\E[?1h\E= is the code to enter key-board transmit mode and rmkx=\E[?1l\E> is the code to leave 'key-board transmit' mode. I couldn't really understand what key-board transmit mode is.
From http://vt100.net/dec/ek-vt220-tm-001.pdf,
7.4.4.1 Keyboard Transmit Mode -- The keyboard codes and a few other special codes are transmitted via a serial line output in PORT of the
8051. The transmitted signal goes from the 8051 to a driver, through the keyboard cable, monitor and video cable to the CPU. A UART within
the 8051 controls the transmission"
I'm getting these codes while entering into and leaving vim, respectively. Can I safely ignore these codes or do I need to handle them? In the latter case, what am I supposed to do?

These two strings contain two sequences each; they control subtly different things:
The first of these,
CSI ? 1h
CSI ? 1l
controls DEC private mode number 1, DECCKM, cursor key mode. This mode determines whether the four arrow keys (Up, Down, Left, Right) will send SS3 or CSI-prefixed sequences.
The second pair of sequences,
ESC =
ESC >
are called DECKPAM, keypad application mode, and DECKPNM, keypad numeric mode. This determines whether the number keypad sends control sequences, or normal numbers (i.e. consider it similar to the Numlock feature).

smkx/rmkx control whether the keypad will transmit numbers or escape code. Also, it is "keypad-transmit-mode" not "keyboard-transmit-mode"

Related

How does one keyboard press lead to different characters, depending on layout

Thank you for taking the time to look at this question.
If you press the ‘y’ key on a keyboard, it is my understanding, that a UTF-8 keycode is sent over USB corresponding to the ‘y’ key. i.e. 0x79 in hex.
This is then interpreted by the computer as the letter ‘y’ and sent to the active window as a keystroke.
My question is, how come when you plug a US keyboard into a German computer, pressing the ‘y’ key results in the letter ‘z’ being sent to the active window.
Now on German keyboards, the letter ‘z’ is in the position which the ‘y’ key is in on a US keyboard. However, if each character has a unique UTF-8 code associated with it, surely pressing the ‘y’ key will generate the ‘y’ keycode (0x79) and this will be interpreted as a ‘y’ by the computer. Surely the location of that key on the keyboard shouldn't matter?
I assume there must be interconversion at some point to account for different layouts. How and at what point does this interconversion happen, is it done by the microcontroller in the keyboard or by the computer when it receives the keycode?
Please feel free to point out any wider misunderstandings in the above questions if they are present.
Many thanks for your time.
There are a couple of things your computer is aware of, first is your keyboard layout, which is usually asked about (in Ubuntu during installation for example) or detected automatically (like in Windows for example) by the default keyboard driver. The second is the system language, or preferred language, or keyboard language depending what its called in your Operating System.
When you plug in your English keyboard, the system recognizes it as an English keyboard and will look for your selected language and map the keys accordingly. I type in both English and Arabic, the keyboard layouts are totally different, and all I do is choose from the my keyboard icon in the taskbar that i want to type in Arabic now, the system still uses my English keyboard but with an Arabic keymap.
Hope this explains it!

Replace any keyboard character(s) with keyboard shortcut or different keystroke

For a project using a barcode scanner I need to know if it is possible to replace a special character like
!
"
§
$
%
=
with different keyboard strokes like
arrow down or arrow up or even shortcuts like
ctrl+a or ctrl+v?
Would be also possible if a specific series of characters resulted in a keystroke/keyboardshortcut,
for instance this text InsertArrowLeftHere would result in this keypress arrow left
Is there any way to make something like this work?
A bar-code scanner (unless is used with special hardware in-between) just reads the data, and sends keystrokes to the computer as keyboard interrupts. How the bar-code "string" is interpreted depends on software that, at that moment, has the focus. If you open a Notepad and read something with the barcode scanner, the number will be printed in notepad. In many cases no software comes with the scanner because there is no need for that.
But your software (the program that receives the data from the scanner) can catch anything typed in the textbox (or other control that has the focus, for example the whole form can catch the keystrokes). Maybe you can also identify where the keystrokes come from, (means: from which keyboard-input device: keyboard1, keyboard2, barcodescanner etc.) and act accordingly (if from keyboard1 or keyboard2 do nothing, if from barcodescanner then do this).

Windows 8.1 Handling Physical Keyboard Input

I'm developing a Universal App in c# for Windows 8.1
I'm trying to catch keyboard input and from the on-line literature have been pointed to KeyDown event and KeyRoutedEventArgs and the Key property. This works fine for most key characters and returns VirtualKey enumerations such as VirtualKey.A. However, when characters such as ,.;:> are pressed the Key property is set to a number and this number is the same value if the key is pressed in combination with VirtualKey.Shift which seems to indicate it is not representative of the characters on the key, but only represents the physical key.
As it happens, I'm using an Italian laptop keyboard which of course is laid out differently to a UK Extended keyboard so the Key value for a semicolon (;) is 186 on a UK keyboard (as an un-Shifted or bottom character) and is 188 on an Italian keyboard (as a Shift or top character). I'm therefore stumped as far a capturing these punctuation characters.
I have developed WPF, Silverlight and .Net app in the past and don't remember it being as difficult to handle physical keyboard input even in combination a game loop, as I just used the Key or Keys enumeration and an OEM value.
How can I capture these punctuation characters when their respective key is pressed, irrespective of the keyboard layout?
Answer provided by Hans Passant (https://stackoverflow.com/users/17034/hans-passant):
Characters typed on a physical keyboard are exposed by this event:
http://msdn.microsoft.com/en-us/library/windows.ui.core.corewindow.characterreceived.aspx

Terminfo smkx and Application Cursor Keys vs Application keypad

XTerm Control Sequences specifies the following key sequences:
CSI ? 1 h → Application Cursor Keys (DECCKM)
CSI ? 1 l → Normal Cursor Mode (DECOM)
CSI ? 66 h → Application keypad (DECNKM)
CSI ? 66 l → Numeric keypad (DECNKM)
and the Terminfo Source Format has the following entry:
Variable: keypad_xmit
Capname: smkx
Termcap: ks
Description: Put terminal in "keypad-transmit" mode
But the terminfo for xterm actually says smkx=\E[?1h\E=, which seems mixed up to me (smkx should affect the keypad, not the cursor keys, right?). What am I missing here?
The line
CSI ? 1 h → Normal Cursor Mode (DECOM)
probably should read
CSI ? 1 l → Normal Cursor Keys (DECCKM)
There are two escape sequences in each of smkx and rmkx because these capabilities are used in curses, i.e., for the keypad function.
The manual page for ncurses (like others) does not say so explicitly, but the function applies to all of the special keys on the keyboard which have the ability to switch between normal and application mode. This is a well-known feature of smkx and rmkx, as for example in the xterm FAQ Why can't I use the cursor keys in (whatever) shell?.
Special keys on the keyboard may include these (depending on the type of terminal):
numeric keypad (on the extreme right of a PC keyboard)
editing keypad (6 keys between the main keyboard and the numeric keyboard)
cursor keys
function keys (commonly at the top of a PC keyboard)
The VT100 (which does not have function keys or editing keypad) has separate escape sequences for the other two categories. In VT220 (emulated by xterm), the editing keypad's normal/application mode is an extension of the VT100 DECCKM, (documented in XTerm Control Sequences). DEC did not define a corresponding feature for function keys; however if there were some terminal which supported this capability it would probably be used in smkx and rmkx.
It looks like you are missing the \E= at the end of smkx.
ESC = Application Keypad (DECKPAM).
ESC > Normal Keypad (DECKPNM).
are listed on the XTerm Control Sequences page as well and you would expect them to affect the keypad.
I found a related question here: keyboard transmit mode in vt100 terminal emulator.

Getting "complete" and "menu-complete" to work together

I found out that the Bash shell supports a type of autocompletion that is different from the "traditional" autocompletion, where all possibilities get listed on the following line.
With the "traditional" autocompletion, if I type ch and then press the Tab key, I get something like:
$ ch
chacl chgrp chmod chown chvt
But if I add the following line to my /etc/inputrc (which remaps the Tab key to the built-in menu-complete function):
Tab: menu-complete
then the behavior of the shell changes: the word to be completed is replaced "inline" with a single match from the list of possible completions, and if I press the Tab key again, the word gets replaced with the next match.
I found this useful, but I still wanted to keep the traditional autocompletion and have it bound to the key combination Ctrl + Tab. So I added the following line to my /etc/inputrc file, according to what the readline library documentation suggests:
Ctrl-Tab: complete
However, adding this line only seems to make both Tab and Ctrl-Tab call the traditional complete function.
Does anyone know what I am doing wrong?
Thanks in advance!
To start with, I'm not a massive expert in this area, but I think I can answer your question. First of all, while you are using Bash, Bash is a shell which interprets keyboard commands that it receives from a terminal / console. While you are informing Bash how to react to specific key combinations in the inputrc file, your Terminal determines precisely which character is 'sent' to the Shell before the inputrc file even enters the equation.
Unfortunately, on my system (granted, it's OSX - but I don't think this is strange behaviour when compared to Linux), both Tab and Ctrl-Tab send the same keyboard input to the shell. Infact, both Tab and Ctrl-Tab send a Ctrl-I command to the shell, and indeed, if I enter Ctrl-I when using the terminal, it performs the completion as if I hit Tab.
The software (installed on most Linux systems by default), showkey will tell you what keys the shell is receiving when you press specific keyboard inputs as you push them.
Anyway, my suggestion to you is to use Shift-Tab, which does appear to send it's own key-code to the shell. Shift-Tab on my computer shows up (using showkey) as '<ESC>[Z', which I think is pretty standard across the board. As such, your inputrc file with the following bindings should allow you to use shift-tab instead of ctrl-tab to achieve what you desire:
Tab: menu-complete
"\e[Z": complete
The \e in the second binding represents the escape character, and the [Z are simply the characters as shown using showkey. You can get a similar effect on OSX by simply using cat, running cat from within a terminal and pressing Shift-Tab will show you "^[[Z", where ^[ represents the escape character and the other characters are as before.
I know this doesn't resolve your question precisely, but as I don't think you are able to use Ctrl-Tab as a key combination, without re-mapping Ctrl-Tab to another keybinding within your terminal (more likely to be easier if you are using a GUI terminal), this is likely as close as you can get without significant effort!
I have ShiftTab bound to menu-complete-backward, so it goes back one step if I skipped the right completion, and I've mapped Ctrlq to complete, so if there are several possible completions I hit Ctrlq to list them without having to cycle through them.
# Make Tab cycle between possible completions
# Cycle forward: Tab
# Cycle backward: Shift-Tab
TAB: menu-complete
"\e[Z": menu-complete-backward
# Make C-q display the list of possible completions
Control-q: complete
# Display the list of matches when no further completion is possible
set show-all-if-unmodified on
Edit: Ctrlq is bound to quoted-insert by default, that is, it tells the shell to take the next key literally. quoted-insert is also bound to Ctrlv, so you don't lose that functionality if you rebind Ctrlq. Anyway, I've found that AltESC also works, by default, for showing the possible completions (as far as I can tell it is equivalent to TAB); note that it may be seized by Gnome, then either double press ESC or rebind "Switch windows directly" in Settings → Devices → Keyboard → Navigation.
The following should achieve what you're looking for (if I understand correctly!)
In your .inputrc
# display all possible matches for an ambiguous pattern at first tab
set show-all-if-ambiguous on
# next tab(s) will cycle through matches
TAB: menu-complete
# shift tab cycles backward
"\e[Z": menu-complete-backward
Where to start, if you can or cant do this is dependent your keyboard and your drivers and there isn't one catch all answer. Each key press and release generates a sequenced key pair (key down and release) (scancode) these codes are then translated by the kernel into keycodes for example on my laptop keyboard 0x3a 0xba are translated to keycode 15 (down and up) these are then translated into actions such as return letter c a / you can assign actions to keysyms using the keycode/hex/binary/octal notation which codes match which letters is determined by the kernel translation table which is fairly standardized, however the first part signal that's translated to keycodes is different for most keyboards.
Continuing with the earlier example for me shift tab (and alt and control and any combination) produce keycode 15 however in hex it produces 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a 0x2a and this is because shift alt and control are special keys (modifiers) these multiply out against the keycodes and fill out the dumpkeys table the kernel is limited to the number of assignments as well this is determined by your choice of keymap and shares resources with your terminal colors (if your char set its defined above the threshold it limits your terminal color scope). And this all goes out the window if your in an xserver and has a whole new system. Most of these things can be changed,modified and manipulated by the user and programs installed. My point to all this is to emphasize that there is no catch all for the mapping of the tab key and its going to vary keyboard drivers to kbd drivers (now if you find a solution that happens to work for you excellent :)) but chances are it won't be portable and might not work if you change keyboards and might not translate between xserver and tui. What i recommend is learning the steps to modify your kbd on the go.
will give you the decimal octal hex notation for a key press on the same line
--full-table -1 >> keytable
will give you a documented with your full list of keycode->keysym pairing in a format that will give you a better picture of your layout and from there you can either use loadkey to change a keys value or ad an entry in .inputrc or your main rc file. You can also create a custom key.map file.
Further escape sequence translation is determined by the "$TERM" variable and each virtual terminal emulator can be different
infocmp "$TERM"
will give you a list of your terminal escape sequences
Resources:
https://man7.org/linux/man-pages/man4/console_codes.4.html
https://www.gnu.org/software/screen/manual/html_node/Input-Translation.html
http://kbd-project.org/docs/scancodes/scancodes.html
https://www.vt100.net/
So to sum up.
Your keyboard drivers
Your kemap choice
Your virtual terminal emulator
and your kernel
form the backbone of remapping dificult keys (tab/s-tab/a-tab)
I'm not sure Ctrl-Tab is a real character; my terminal, for instance, ignores the combination. I think the only way to use Ctrl-Tab is to use your terminal emulator to map it to some otherwise unused escape sequence, then bind that sequence to complete.

Resources