

-----------------------------------

rated

Tue May 20, 2008 8:18 pm


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! :)


-----------------------------------

Insectoid

Tue May 20, 2008 8:20 pm


RE:Exit Program when User presses Esc

-----------------------------------

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

look into the character control tutorial


-----------------------------------

rated

Tue May 20, 2008 10:05 pm


Re: Exit Program when User presses Esc

-----------------------------------

is there way to do this using getchar


-----------------------------------

gitoxa

Tue May 20, 2008 10:14 pm


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.

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

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


-----------------------------------

rated

Tue May 20, 2008 10:14 pm


Re: Exit Program when User presses Esc

-----------------------------------

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


-----------------------------------

richcash

Wed May 21, 2008 4:07 am


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).

loop
    exit when getchar = chr (27)
end loop


-----------------------------------

rated

Wed May 21, 2008 3:44 pm


Re: Exit Program when User presses Esc

-----------------------------------

chr (27).

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 :(


-----------------------------------

StealthArcher

Wed May 21, 2008 3:49 pm


RE:Exit Program when User presses Esc

-----------------------------------

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


quit when getchar=chr(27)



-----------------------------------

andrew.

Sat May 24, 2008 8:42 pm


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:

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.

