Author |
Message |
rated
|
Posted: 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 Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
rated
|
Posted: Tue May 20, 2008 10:05 pm Post subject: Re: Exit Program when User presses Esc |
|
|
is there way to do this using getchar |
|
|
|
|
![](images/spacer.gif) |
gitoxa
![](http://compsci.ca/v3/uploads/user_avatars/125344263047f801d546bcb.jpg)
|
Posted: 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 |
|
|
|
|
|
![](images/spacer.gif) |
rated
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
richcash
|
Posted: 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).
|
|
|
|
|
![](images/spacer.gif) |
rated
|
Posted: 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).
[/quote
the problem with using exit is that it exits the loop, I want the entire program to end ![Sad Sad](http://compsci.ca/v3/images/smiles/icon_sad.gif) |
|
|
|
|
![](images/spacer.gif) |
StealthArcher
![](http://compsci.ca/v3/uploads/user_avatars/18949255664b176c4f1481b.jpg)
|
Posted: 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)
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
andrew.
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
|