testing for <esc> key
-
Hi all, I need to abort a procedure upon the user hitting the key. Could anyone point me in the right direction on how to implement it? Thx, Ralf. ralf.riedel@usm.edu
-
Hi all, I need to abort a procedure upon the user hitting the key. Could anyone point me in the right direction on how to implement it? Thx, Ralf. ralf.riedel@usm.edu
Well, if it's a console app (not sure for others... may or may not work) you can do something like the following: if (kbhit()) { if (getch() == 26) { // escape key was pressed! } } And I believe you have to include conio.h. Also, I'm not positive 26 is the escape key... but my gut says it is. And if you are costantly looping through that code, you will know when the escape key was pressed. Good luck. If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
-
Hi all, I need to abort a procedure upon the user hitting the key. Could anyone point me in the right direction on how to implement it? Thx, Ralf. ralf.riedel@usm.edu
You need to either run your procedure in a seperate thread or use GetAsyncKeyState. To check for escape, I reckon the constant is VK_ESC, but that's a guess. This function tells you if a key was pressed since it was last called, so call it, then do something like: if (GetAsyncKeyState(VK_ESC)) { // finish off and go home } Actually, the most significant bit is set if the key is down now, and the least significant MAY be set if it has been pressed, so MSDN tells me. The above is how I always did it, and I'd say it's more efficient than bit mashing over and over inside your process. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Well, if it's a console app (not sure for others... may or may not work) you can do something like the following: if (kbhit()) { if (getch() == 26) { // escape key was pressed! } } And I believe you have to include conio.h. Also, I'm not positive 26 is the escape key... but my gut says it is. And if you are costantly looping through that code, you will know when the escape key was pressed. Good luck. If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
Escape is 27, from memory. However, it's bad to rely on these values, you should use the virtual key constants instead. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
You need to either run your procedure in a seperate thread or use GetAsyncKeyState. To check for escape, I reckon the constant is VK_ESC, but that's a guess. This function tells you if a key was pressed since it was last called, so call it, then do something like: if (GetAsyncKeyState(VK_ESC)) { // finish off and go home } Actually, the most significant bit is set if the key is down now, and the least significant MAY be set if it has been pressed, so MSDN tells me. The above is how I always did it, and I'd say it's more efficient than bit mashing over and over inside your process. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
You need to either run your procedure in a seperate thread or use GetAsyncKeyState. To check for escape, I reckon the constant is VK_ESC, but that's a guess. This function tells you if a key was pressed since it was last called, so call it, then do something like: if (GetAsyncKeyState(VK_ESC)) { // finish off and go home } Actually, the most significant bit is set if the key is down now, and the least significant MAY be set if it has been pressed, so MSDN tells me. The above is how I always did it, and I'd say it's more efficient than bit mashing over and over inside your process. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder