Catching special characters with ncurses - linux

I am currently working on a project for mapping every possible keyboard and mouse interrupt.
The mapping is done in linux environment and with ncurses library.
The question is how to catch the following keyboard keys :
Home
End
page up / down
when pressing those keys the terminal itself is catching them and the program itself cant see them (spent a few hours of configuration and found no solution yet)
pause/break (above page up in standard keyboard)
PrtScreen
Num Locked keys (0 to 9 and < . >).
Windows button
the following just not getting any response at all, neither from the terminal or the program.

short: you cannot catch all keys with ncurses
long: the usual problems lie in a failure to initialize things properly:
you probably forgot to call keypad(stdscr,TRUE) (or whatever window you might be using with wgetch). That will allow an application to read any of the keys defined in the terminal description as an integer.
If it is not in the terminal description, (n)curses will return the sequence of bytes which make up the key as sent from the keyboard.
That's two likely problems. There are other keys (or combinations of keys) which the terminal will not send (in a way which makes distinct keyboard sequences). For instance, using the Control key with other keys may change the sequence sent by the keyboard, or it may not. To see this, use experiment with the control key with comma, period or the other punctuation keys in that area of the keyboard.

Related

How to read characters with out pressing enter key in c++

I am writing a small game program in c++, which requires user to press some keys from keyboard. The problem with 'cin>>' or cin.get() is that it requires user to press enter to read data into memory. So, please help me to read key strokes with out pressing enter key. I work on Linux.
maybe you can use ncurses library?
By default the terminal is buffered and is in "cooked mode" where individual key presses are not sent to the application immediately.
You might be able to use something like GNU readline for input, or you could use ncurses for input and output, or if you just want to receive every key as it's pressed you could put the terminal into raw mode and do everything manually using the cfmakeraw function.

When you press right arrow in terminal during a process "^[[C" shows up. What it means anyway?

If you happen to press arrows in Linux terminal while running a mysql query or inside a window where you have a server running a series of characters pop up. The same thing happens if you press the arrows + SHIFT or F2, F3, F4, etc. But if you press other keys they will show up as you would expect.
It is obvious to me that these sequence of characters were created following certain order. So what are they? What do they represent? Who came up with them ? Which computer language do they come from? They look archaic and useless...Should we drop them in the future? Or are they really useful?
4 Arrows
^[[A^[[B^[[C^[[D
SHIFT + Arrows
[[1;2A^[[1;2B^[[1;2C^[[1;2D
F2-F6
^[OQ^[OR^[OS^[[15~^[[17~
I searched for an answer to my questions on the web to no avail.
Actually, that is from a terminal emulator. The Linux console produces different characters.
In either case, those are generally referred to as ANSI escape sequences, which are sent by special keys (function-keys or cursor-keys), usually in the same type of "archaic" form which applications use to control the terminal.
The particular set you have quoted are documented in XTerm Control Sequences, and are recognized by terminal applications such as ncurses. The corresponding information in ncurses is stored in its terminal database, e.g., this entry (you may have to follow a few links to see all of this).
With that, you may have enough keywords to use with web-searches.

Creating your own LaTeX keyboard layout : 1 key = multiple caracters

I've been looking for the answer for quite some time now. This is a project I have but I can't manage to find a way to do it. The main idea would be to plug an additional keyboard on my computer that write multiple letters by hitting only one key. For example, instead of writing down a (when I hit the a key), it would write \textbf{ (for example).
I already manage to find the keyboard layout file under Linux and to switch the a and b keys, but I cannot find a way to print multiple characters.
I know it exist editors (like Texmaker or Kile) that have auto-completion, but I'm most of the time working in project in groups and therefore we use writelatex.com which does not propose auto-completion in it's free user pack ! Besides, I'm doing that for my personal interest.
Thanks a lot.
Have a look at autokey. It can assign phrases to hotkeys. It requires X11.
Another option might be to use a powerful text editor like vim or emacs which both have features like this, and then copy/paste the text into writelatex.com.
Some browsers have add-ons that allow you to edit the contents of a text field on a web page with a chosen text editor.
Edit: In Xorg you can use the X KeyBoard extension to e.g. change the meaning of individual keys. While you can configure the keyboard to generate (multibyte) unicode characters, you cannot assign arbitraty character strings to one key, to the best of my knowledge.

Cygwin alway's interpreted with Ctrl-C

My cygwin terminal (known as Mintty) can't work, when I minimize it to the windows taskbar, and restore it, and it will receive the Ctrl-C signal, but i didn't touch any key.
This is wierd. when a long time command is running, i swith it to see wether is finishe, then it is interputed my Ctrl -C. I refresh intall it several times. it's still there.
This situation can also happened when i select some text on the terminal.
Thanks
Some translator software have the "Hyper Translate" function, which will copy texts selected then tries to translate it, the way how it copy strings is to simulate a Ctrl-C from keyboard. When using cygwin or some ssh/telnet terminal tools (e.g. SecureCRT, putty, NX Client..) and the Ctrl-C is not set as the hotkey for copy action, and you tries to select a block of texts, trouble comes.
I guess the one who asking this question is also a Chinese like me. Then, the famous software which will bring this trouble is "Youdao Dictionary".
Disabling the "Hyper Translate / HuaCiFanYi" function of the "Youdao Dictionary" is a remedy.
As Leif Zhang mentioned, if you are using Lingoes or other dictionary you should uncheck the option Translate Selected Text as the following image.

Linux single key presses triggering multiple-key combinations

I understand that new keyboards can be ordered online, but now that this problem has proven to be hard I am completely fascinated by it.
Many old laptop keyboards as they wear develop consistent shorts which cause multiple keys to react when a single key is pressed. For example, on my little sister's computer if you press "r" the system outputs "vr", "i" outputs ",i" and so-on.
Assuming the user is not a vim/emacs power user, the keyboard still seems salvageable. It seems that if the keyboard driver was changed so that pressing the "r" key resulted in the computer accepting "backspace r" the "v" would disappear and not be such a hassle anymore.
Xmodmap XKB and other systems seem to assume that each single key depression will result in a single command. Does anybody understand the missing link where more than one character can come from a single keypress? There seem to be many places in the stack where this can be pulled off, but none of them are particularly clearly documented. Another fun fact is that you can't force this in the ubuntu keyboard shortcuts editor, ubuntu will stop you from entering the changes there under the premise that "this will make it impossible to type."
Hacking around in xev shows that the computer believes that when you hit and release 'r' that it gets a keypress event for 'v' then a keypress event for 'r' then a keyrelease event for 'v' then one for 'r'. If you could change the configuration to ignore a first keypress if there is no corresponding key release before the next key is pressed, that would work too.

Resources