Computer Science Canada

Exit Program when User presses Esc

Author:  rated [ Tue May 20, 2008 8:18 pm ]
Post subject:  Exit Program when User presses Esc

Hello,

I am writing a program and would like to know how to make the program exit when the user presses the 'ESC' button on the keyboard

Thanks! Smile

Author:  Insectoid [ Tue May 20, 2008 8:20 pm ]
Post subject:  RE:Exit Program when User presses Esc

Input.KeyDown (key)
exit when key (KEY_ESC)

look into the character control tutorial

Author:  rated [ Tue May 20, 2008 10:05 pm ]
Post subject:  Re: Exit Program when User presses Esc

is there way to do this using getchar

Author:  gitoxa [ Tue May 20, 2008 10:14 pm ]
Post subject:  Re: Exit Program when User presses Esc

If you set up a simple program to get a key from the user, you can find the ordinate value of any key they input. Having said this, you can easily find the ordinate value of the escape key. Once this is found, you can simply check the ordinate value of the key the user presses to see if it matches the one ordinate value of the escape key.

Use the ord function.

code:
var Sample : string(1)
Sample := "b"

ord("A") = 65
ord(Sample) = 98

Author:  rated [ Tue May 20, 2008 10:14 pm ]
Post subject:  Re: Exit Program when User presses Esc

elsif question = 'KEY_ESC'
then
exit
doesnt seem to work

Author:  richcash [ Wed May 21, 2008 4:07 am ]
Post subject:  Re: Exit Program when User presses Esc

The escape key's ASCII value is 27. That means you represent the escape key with chr (27).

Turing:
loop
    exit when getchar = chr (27)
end loop

Author:  rated [ Wed May 21, 2008 3:44 pm ]
Post subject:  Re: Exit Program when User presses Esc

[quote="richcash @ Wed May 21, 2008 4:07 am"]The escape key's ASCII value is 27. That means you represent the escape key with chr (27).

Turing:
loop
    exit when getchar = chr (27)
end loop
[/quote

the problem with using exit is that it exits the loop, I want the entire program to end Sad

Author:  StealthArcher [ Wed May 21, 2008 3:49 pm ]
Post subject:  RE:Exit Program when User presses Esc

If it wasn't so frowned upon, I WOULD say

code:

quit when getchar=chr(27)

Author:  andrew. [ Sat May 24, 2008 8:42 pm ]
Post subject:  RE:Exit Program when User presses Esc

Make a variable called exitgame and have it so that when you want to have the game exit, it becomes true. So each loop would have an if statement before it. Like this:

Turing:
var exitgame : boolean := false

if exitgame=false then
     loop
          blah blah
          if getchar=chr(27) then
          exitgame := true
          exit
     end loop
end if

if exitgame=false then
     loop
          blah blah
          if getchar=chr(27) then
          exitgame := true
          exit
     end loop
end if


Something like that.


: