Hot keys

Can I create hot-keys in C++?
IF yes .How?
Last edited on
Of course.
Can you be more specific? (Hot keys for what?)
can you tell me what are hot keys ?
Microsoft calls them "shortcuts" or "shortcut keys".
Except they need not be Alt+something.
Last edited on
Duoas ,I mean if some task is going on & I want to stop or change it abruptly by a any key (hot-key) ,then what should I do?
Is there any function or specific code?
Please reply
It depends entirely on what subsystem you are using. Can you be more specific?
What do you mean by sub-system?
What kind of project are you making? Is it command line only? Is it Win32 API GUI? Is it GDI+? What operating system are you on? Is it cross platform? Do you like milkshakes? If so what flavor? What IDE are you using? What are you wearing?
I m using Turbo C++,command line programing & OS is Windows XP
OK, we are getting closer.
How are you getting input from the user in your console application? Are you using a Win32 messaging loop or are you using cin and the like?

(The trick is, you must use some form of input loop: either a Win32 messaging loop or loop over ReadConsoleInput().)
I am using cin
I'm sorry to ask so many questions, but playing with the console like this is tricky. What exactly do you want these hotkeys to do? You said:
I mean if some task is going on & I want to stop or change it abruptly by a any key (hot-key)
can you explain further? What do you mean by "task".

(As it is, a complete program is a "task" to Windows, and you can abort a task, but there is no such thing as "foreground" and "background" tasks like on Unix.)
I have made a program of scrolling. Scrolling is in infinite loop. Now , I want to stop scrolling by pressing some key defined in program . How can I do this?
Last edited on
I think you need to create an event handler.
to do it in native C++ take a look at this reference:
http://msdn.microsoft.com/en-us/library/ee2k0a7d.aspx
yes. .it can be done by event handler .. but how do i create it in c++ only ..
Last edited on
Those are not orthogonal questions. C++ does not provide you with any OS subsystems. C++ allows you to access them, however.

If you want to play with the keyboard using a non-streams approach, you must use the native OS's methods.

The two basic answers are:

  1 you must use an event loop
  2 you must use threads

Either way, you have a bit of a learning curve ahead of you. The threads scheme is a bit more flexible (there is more than one way to observe or intercept input and communicate back to the program task), but it is also a good bit more involved.

The input loop, as I have already posted, is your most likely friend.
Last edited on
Topic archived. No new replies allowed.