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
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?
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'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?
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.