Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Exit Program when User presses Esc
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rated




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: 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
rated




PostPosted: Tue May 20, 2008 10:05 pm   Post subject: Re: Exit Program when User presses Esc

is there way to do this using getchar
gitoxa




PostPosted: 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
rated




PostPosted: 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
richcash




PostPosted: 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
rated




PostPosted: 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
StealthArcher




PostPosted: 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)
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: