I need to disable the task keys for both Linux and windows using a C program . I tried using the windows.h but as the name states it is not working for the Linux and in case of windows also its not working properly . I tried to do this using the GetAsyncKeyState function but still have no clues to Linux key handling. As I am new to system code I have referred to following but unable to get through the issue.
So please suggest some solution that could be helpful in handling keys (Enable/Disable) on both platforms (Linux/Windows) ?
And is it okay to use key-scan codes and ASCII codes for the Key event handling?
I have already referred to :
Disable task switching keys with c++
Disable keyboard keys when the console of c Run using c or c++
How to handle key press events in c++
If you are looking for low level, cross platform keyboard handling then you might want to have a look at libsdl - http://www.libsdl.org/. The keyboard handling section is - http://wiki.libsdl.org/CategoryKeyboard
Related
Right now my "change virtual desktop" keyboard shortcut does not work on Windows 10. It is normally bound to ctl + ➡️ by Windows.
I have tried resolving the issue by guess and check to no avail. Further, I and other StackExchange users have had similar problems with VSCode, Windows, Internet Explorer, etc.
I would like a general method for listing keyboard shortcut / hotkey bindings on Windows so I and other can reliably diagnose any issue like this in the future. Command line solution is preferred, but a programmed or GUI solution is acceptable.
The process I'd like to follow is:
List all hotkey bindings on my Windows instance
Identify if there is a conflicting hotkey binding or if the root cause is different
De-conflict the hotkey binding
Profit
I do not want the solution of only using Safe Mode because it does not give me the precise information I want quickly. I do not want a guess and check solution. Windows OS knows what the hotkey bindings are, so there must be a way for Windows to tell me what they are, otherwise how would Windows know?
I have tried the following:
Disabling possibly conflicting background applications
Searching YouTube, Reddit, StackExchange, Google
Reviewed the Microsoft Docs:
1. How to Retrieve and Set a Hot Key - didn't understand the code sample due to lack of Win32 C++ experience; code sample didn't solve my problem
2. RegisterHotKey function (winuser.h)
- sets a hotkey, doesn't get it
3. UnregisterHotKey function (winuser.h)
- unsets a hotkey, doesn't get it
4. WM_GETHOTKEY message
- didn't understand how to use
3. WM_SETHOTKEY message
- don't think this solves my problem
Im writing a little C++ progam but got to a point from which on i could not go on:
I want my program to control an external program using a certain combination of keys.
Yes, this sounds like a horribly unclean workaround, but thats what i want to do ;)
To be more specific:
I want my little C++ program to control the already running program elinks (a text based internet browser) by pressing the "esc" then "v" and then "h" -keys (this is used to toggle between html and plain text output in elinks).
But unfortunately, I do not know how to get a C++ program to type a certain combination of keys (...if this is possible at all).
I already tried the search function but wasnt able to find a solution.
It would be very kind of you, if someone could give me a hint on what to do here.
Thanks,
Spoekenkieker
P.S.: Im running Linux
If you have control over how to start the elinks browser, you can start it under the GNU screen terminal multiplexer and use its stuff command to send key inputs:
https://unix.stackexchange.com/questions/13953/sending-text-input-to-a-detached-screen
This way you're not required to learn the complications of X Windows programming.
We've been struggling for a while now to understand the keyboard scancode behavior in Linux.
When we open a normal bash shell, the arrow keys works as expected: UP shows the previous item in the history etc. However when you spawn a process, arrows does not work as expected anymore. For example, UP prints ^[[A instead of the previous command.
To demonstrate this, do something like:
bash$ ping www.google.com
Now, press UP or DOWN etc. and you will see the wrongly mapped key codes while the process is running. However, when you terminate the process the arrow keys will work again.
We've tested it on CentOs, Ubuntu, Mac and even in different shells (bash, sh, zsh) and the same happens everywhere. I've also tried different keyboard modes using kbd_mode where we tested with RAW and XLATE modes.
The closest thing I could see while searching for answers were IPython users have experienced the same behavior when IPython was not build against readline. However, this is not related to our case as far as I can see.
We are developing a C++ Tcl based console application which uses cin and cout to communicate with, and get input from the user. We are having issues with the arrow keys when we try to access the history of previously entered commands. This is a major issue for us as 99% of people expects the arrow characters to just work.
Any ideas on how we could overcome this would be much appreciated.
You must set the terminal into raw mode to get the scan codes and handle them (that is: disable ICANON, you want the non-canonical mode). You probably also want to disable ECHO (so that it doesn't print your input on the terminal).
That is what readline or linenoise are doing. See here for some code. Esp. see the function linenoiseEnableRawMode. Some other simple sample Python code is here where I have written a simple console media player which checks for the keypresses left ("\x1b[D") and right ("\x1b[C").
The relevant calls are to tcgetattr (to get the current terminal state and modify that state struct to get into raw mode and enable some other useful behavior stuff) and tcsetattr (to set the state).
readline, libedit or linenoise are some libraries which do all that work for you and provide you with history, autocompletion, etc.
At the end, you must restore back the old state, otherwise you get the behavior you are describing in your shell.
I want to monitor when a key is changed/added/deleted to the registry whenever application is being installed or removed. I have tested the sample code from the msdn(link) and it works fine.
But the problem is that it does not tell me which key has actually been modified/added/deleted. How can i retrieve this information using c++?
There are only 3 ways, none of which is both easy and adequate:
RegNotifyChangeKeyValue:
Doesn't give you the info you need, but is very easy to use.
EVENT_TRACE_FLAG_REGISTRY which is part of Event Tracing for Windows
which is what ProcMon uses. It works well, but it's quite difficult to use.
I'm not sure exactly how to use it myself, but if I figure it out I'll post it here.
CmRegisterCallback:
Requires kernel-mode driver, which is a pain in 64-bit.
But it's the most perfect solution otherwise.
Unfortunately Event Tracing for Windows (EWT) does not allow to see full key path in the event. You get only a partial key name and a strange handle with is actually a key control block. It's not so simple to get information from this block.
Yes the process monitor uses EWT, but it does not use Windows Kernel Trace as a provider.
I'm currently developing various console games in Windows that won't really work using regular input via cin.
How can I (In a simple way using only standard windows libraries available in MSVC):
Make the program wait for a (specific?) key press and return the key ID (It would have to work for all keys including the arrow keys)
During a real-time game check for the last pressed key of the user and if there was any key pressed since the last check.
It would really help if you could include a short example program for your solution
I've got just what you need.
Here enjoy pal:
C++ source
It's pretty much self-explanatory but if you have any doubts my email is jacobossm#gmail.com
AFAIK you can't do it using the standard C runtime. You will need to use something such as the Win32 function GetAsyncKeyState.
You want the Windows Console API, for example PeekConsoleInput.