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.
Related
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.
I have the script:
#F20:: ^!{DEL}
which is suppose to simulate pressing CTRL+ALT+DELETE"
I Viewed the event log and the order in which the keys simulations are sent is completely messed up! What have i done wrong and how can i achieve the desired affect?
Just did some digging, unfortunately Windows does not allow for simulation of Ctrl + Alt + Del. If you want the task manager it brings up simply use:
#F20::Run taskmgr
As ahkcoder pointed out Windows keeps Ctrl+Alt+Del out of reach, see
https://autohotkey.com/docs/commands/Send.htm#Remarks
Apart from that the order of your key history is correct. It's just interspersed with other keys you pressed, likely because your script uses the keyboard hook.
Which in turn would prevent your #F20 Hotkey to work if it is itself triggered from a script. Without seeing your actual script that's about as much as i can think of.
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.
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.
Forgive me if this is a silly question but I am a novice programmer, and I'm hoping there is a novice solution to this.
Is there any programming language that will quickly allow me to write a simple program to show a notification on Windows 7 when CAPS LOCK is pressed?
My laptop doesn't have an indicator light and I have no program on my computer to do so, although I'd be open to suggestions. The only partial solution I've found is through accessibility settings in Windows which plays a god-awful beep every time the key is pressed.
Thanks!
Try Auto Hotkey. It is a great program just for that. It runs scripts in the background that can directly manipulate your keyboards input.
I changed capslock to require ctrl+capslock to work otherwise pressing capslock by itself does nothing :)
You can also do a bunch of other things. You are able to set a custom tone for when you push capslock (however a simple popup or key remapping would probably be best).
Here's an example from the site:
"Capslock::Ctrl Makes Capslock become a Control key. To retain the ability to turn Capslock on and off, also add the remapping +Capslock::Capslock (this toggles Capslock on and off when you hold down the shift key and press Capslock)."