Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm writing a Windows program and I need to register a hotkey. However, I'm afraid of the conflicts caused by RegisterHotKey().
Furthermore, Key Events are blocked when you triggered a Hotkey message. For example, you call RegisterHotkey(0, 0, MOD_NOREPEAT | MOD_ALT, VK_UP) To register hot key ALT + ↑. If you press ALT + ↑ in explorer.exe, explorer.exe won't receive this message(Originally ALT + ↑ is go up a level in explorer.exe).
Is there a way to register hot key without conflicts and blocking?
The MSDN page for RegisterHotKey says:
RegisterHotKey fails if the keystrokes specified for the hot key have
already been registered by another hot key.
along with:
Return value
Type: BOOL
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
In other words, if(!RegisterHotKey(...)) ... deal with error ... would catch various forms of "didn't work", including that the hotkey is already in use - you need to look at GetLastError to tell the difference between "key already in use" and others.
I think the whole point of registering a hotkey is that YOUR application ALWAYS gets that keypress, regardless of what is going on. Which of course is a bit annoying if it happens to be popular key in some other application, but it's still the point of registering a hotkey. If you don't like that effect, then don't register a hotkey, or use a more obscure combination that is less likely to be used by some other application. Not sure how else this can be solved - exactly what would you like the system to do if you run IE together with your application, and ALT-uparrow is pressed?
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a windows c++ application which runs under the normal (non-admin) user. I want that no user should be able to close/stop/terminate this application by any means.
Is there any active directory group policy available to achieve this or I need to do some programming for the same
The only way I know is that your app will launch run 2 or more background processes that check every few ms that your app and the other backgrounds are running, if not it re-launches them.This makes it very had or impossible to terminate your app manually.
You application might need to save its state to disk , if it needs to re-launch to the same stat is was when destroyed
you can also disable the close button or whatever can terminate your application. Also disable the taskmanager so users cannot kill your application
There is a technique called hooking which will allow injection of your code into Windows DLL's, altering certain behaviours performed by the operating system.
This would prevent the operating system killing these proccesses using the core DLL's.
There is a downside to this method though as it may flag up as a virus on anti-rootkit systems as this is a technique often used to prevent the user from killing an infection.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a Mac, so I don't have access to any windows.h functions, or any other windows libraries in C++. I am creating a game in C++. The controls of the game are the characters w,a,s,d. Currently I have the input method as std:cin. However, the problem is after the user types each character they must hit enter every time. Furthermore, the fact the std::cin does not timeout means that the user can essentially 'pause' the game to think about what move to make next (which ruins much of the fun of this game).
I need a function like std::cin but with a timeout of about .25 seconds. A function that will return as soon as the user types the character (without the need of the user hitting enter) would also work; but a function like std::cin with a timeout would be preferred. Please don't suggest window's library functions as I am again a Mac user using terminal.
Are there any standard c++ functions within the standard mac Libraries which will function equivalently to std::cin with a timeout of T that will run correctly in a Mac terminal?
Any reason you can't use int istream::get() ?
It's a blocking call though. I'm sure there is a better way to do it, but the quickest hack I can think of is to spawn a thread (just before calling get()) that waits for 0.25 secs and then writes some 'timeout char' say 't' to teh stream.
You can use the ncurses library, putting the terminal in cbreak() (non-blocking) mode, and disabling input delay with nodelay():
WINDOW *window = initscr();
cbreak();
nodelay(window, TRUE);
Then the getch() function will not block, returning ERR if no character is ready, so you can poll it in a loop and break when your timeout has been reached.
However, this may also require that you use ncurses for screen output, which may be a dealbreaker.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have been thinking how to listen keys and key combinations in Linux (and C/C++). My program structure is following:
Get text input. If ctrl + [somekey] is pressed, print text from a file called somekey.txt.
For example if you press ctrl + a the program should print the text from a file called a.txt.
If ctrl + alt + [somekey] pressed: the program saves already given (not pressed enter) text input to a file called somekey.txt. Example: ctrl+alt+a --> before typed text to file called a.txt. It should also replace the old text in the file if excist. It can be done by force-creating the file.
I have no idea which library I should use. Maybe sdl or ncurses? The program can also be written in some other languague as long as the program stays lightweight to run in Computers like Raspberry Pi. Could someone write me a little code which follows this structure? Thanks in (code) advice!
If you go down the SDL route, it should be pretty simple. In general, your program will have a flow like this:
Initialize SDL
Event loop
Wait for event
Handle event, possibly exiting loop
Shut down SDL
In that “handle events” step, you'll probably want to check to see if the event is a keyboard event, and if it is, switch on what modifier keys are held down. Then you can perform whatever logic is necessary.
See the documentation, and in particular the keyboard category for more information.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am connecting to machine using Telnet function, pushing some file to it using Putty and till date it worked fine. But now all of sudden, it has started throwing me an error while I am trying to push some file to the machine using subprocess.Popen().
The error is :
Result: WARNING - POTENTIAL SECURITY BREACH!
The server's host key does not match the one PuTTY has
cached in the registry. This means that either the
server administrator has changed the host key, or you
have actually connected to another computer pretending
to be the server.
Update cached key? (y/n, Return cancels connection) Connection abandoned.
Lost connection
I want to add one step in my scrip that, if console has something like this, then it enter "Yes/y" on console.
I have tried this thing to make it over :
if 'Result: WARNING - POTENTIAL SECURITY BREACH!' in sys.argv:
raw_input("y\n")
time.sleep(1)
But it is not working.. Any help on this!!!
For the first part of your question, you should look in the Registry key HKEY_CURRENT_USER\SoftWare\SimonTatham\PuTTY\SshHostKeys to remove the host computer whose host key has changed (see https://superuser.com/questions/197489/where-does-putty-store-known-hosts-information-on-windows).
For the second part, raw_input() is used to get input from the user, not for submitting values to a subprocess. I'm not sure, but I think that PuTTY's pscp would be getting it's y/n value from stdin, so you could either use subprocess's Popen() to always pass in a "y" just in case (see Python - How do I pass a string into subprocess.Popen (using the stdin argument)?) or you can try passing pscp the "-batch" argument, which sounds like it shouldn't prevent the prompt (see http://the.earth.li/~sgtatham/putty/0.62/htmldoc/Chapter5.html#pscp-usage).
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am coding on Putty (in C++ for what it's worth) and I am currently encountering an error that gives me a really long stack trace. Apparently, the trace is so long that Putty won't let me scroll to the very top where it originated (where I typed "make"). Is there any way around this (except by obviously fixing the error)?
There are two ways.
Change the Window buffer size. Open Putty, load the connection (don't double-click or hit open), click on Window on the left panel and increase the Lines of scrollback to something like 3000 (I think the default is 200).
Same way, load the connection, and then on the left panel under Session you will have the sub-category logging where you can set a file where the entire session history will be recorded.
To increase the lines of scrollback, before you make a putty connection, click on the category Window and increase the lines of scrollback to 10000 or 20000 as may suit you.