Hot keys

Nov 12, 2011 at 2:20pm
Can I create hot-keys in C++?
IF yes .How?
Last edited on Nov 12, 2011 at 2:22pm
Nov 12, 2011 at 4:59pm
Of course.
Can you be more specific? (Hot keys for what?)
Nov 12, 2011 at 6:16pm
can you tell me what are hot keys ?
Nov 13, 2011 at 1:16am
Microsoft calls them "shortcuts" or "shortcut keys".
Except they need not be Alt+something.
Last edited on Nov 13, 2011 at 1:16am
Nov 13, 2011 at 12:48pm
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
Nov 13, 2011 at 9:19pm
It depends entirely on what subsystem you are using. Can you be more specific?
Nov 14, 2011 at 4:34pm
What do you mean by sub-system?
Nov 14, 2011 at 7:12pm
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?
Nov 15, 2011 at 5:29am
I m using Turbo C++,command line programing & OS is Windows XP
Nov 15, 2011 at 9:20pm
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().)
Nov 15, 2011 at 11:17pm
Nov 16, 2011 at 11:28am
I am using cin
Nov 17, 2011 at 8:48pm
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.)
Nov 18, 2011 at 8:43am
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 Nov 18, 2011 at 8:44am
Nov 18, 2011 at 10:01am
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
Nov 18, 2011 at 4:52pm
yes. .it can be done by event handler .. but how do i create it in c++ only ..
Last edited on Nov 18, 2011 at 4:53pm
Nov 18, 2011 at 9:35pm
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 Nov 18, 2011 at 9:36pm
Topic archived. No new replies allowed.