Having a certain command throughout entire code

Is it possible to have a certain command throughout the entire code?
For example if at any time f9 is clicked, the program shuts down what it's doing and starts over, or a friendly message pops out or something like that...
Just simple curiosity not for a project
Also a similar question: is it possible to make a loop stop if at any time during the loop ESC is clicked? The only way I know right now stops it only at the specific time in the loop
Last edited on
Question 2
Found some very old code, but it still works - probably only under Windows.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

#define ESC 27

int main ()
{
  printf ("Hit Escape to stop the loop.\n");
  while (1)
  {
    putch ('.');
    if (_kbhit () && _getch () == ESC)
    {
      printf ("\nOK , cancel it now");
      break;
    }
  }
  _getch ();
  return 0;
}


Last edited on
Topic archived. No new replies allowed.