1. Get_key
- Posted by "Wallace B. Riley" <wryly at MINDSPRING.COM> Aug 28, 1997
- 598 views
I'm puzzled about the proper use of 'get_key'. I am writing a program that wants to know, at some point, what I want it to do. It has a 'get_key' command. If I press Q, it means 'quit' and the program is aborted; if I press any other key, it means 'exit' the subroutine and continue with another part of the program. What does the program do while waiting for me to press the key? It probably involves some clever combination of 'while' or 'elsif' or some such thing, but I haven't figured out just what it should be yet. Or maybe I shouldn't use 'get_key' at all, in which case what should I use? Wally Riley wryly at mindspring.com
2. Get_key
- Posted by Bryan Watts <BWatts1 at COMPUSERVE.COM> Aug 28, 1997
- 601 views
Wallace B. Riley wrote: >I'm puzzled about the proper use of 'get_key'. I am writing a program that >wants to know, at some point, what I want it to do. It has a 'get_key' >command. If I press Q, it means 'quit' and the program is aborted; if I= >press any other key, it means 'exit' the subroutine and continue with >another part of the program. > >What does the program do while waiting for me to press the key? > >It probably involves some clever combination of 'while' or 'elsif' or so= me >such thing, but I haven't figured out just what it should be yet. Or maybe >I shouldn't use 'get_key' at all, in which case what should I use? Wally, are you saying that you are going to ask a question, and the computer needs an answer (such as: puts(1,"Would you like to quit? <y/n>"= ) = If that is the case, try using wait_key() It stops execution until the user presses a key. I'm not sure what you're looking for, but I wrote a function a little while ago that will let you pass a sequence of valid keypresses = to it, and it will return whichever one the user pressed. Here it is: -------code starts here--------- --CHECK.E Author: Bryan Watts global function check(sequence look_for) integer k, m m =3D 0 while m =3D 0 do k =3D get_key() m =3D find(k, look_for) end while return look_for[m] end function --usage sequence junk puts(1,"Please press y, n, or q now.") junk =3D check({'y','n','q'}) if junk =3D 'y' then puts(1,"You pressed yes.") elsif junk =3D 'n' then puts(1,"You pressed no.") elsif junk =3D 'q' then puts(1,"You chose to quit.") end if -------end code-------- I hope this helps a little. Regards, Bryan Watts
3. Re: Get_key
- Posted by Robert B Pilkington <bpilkington at JUNO.COM> Aug 28, 1997
- 597 views
- Last edited Aug 29, 1997
>I'm puzzled about the proper use of 'get_key'. I am writing a program >that wants to know, at some point, what I want it to do. It has a >'get_key' command. If I press Q, it means 'quit' and the program is aborted; >if I press any other key, it means 'exit' the subroutine and continue with >another part of the program. > >What does the program do while waiting for me to press the key? >It probably involves some clever combination of 'while' or 'elsif' or >some such thing, but I haven't figured out just what it should be yet. Or >maybe I shouldn't use 'get_key' at all, in which case what should I use? You should use wait_key(). It does what your idea is, but better. (Read the LIBRARY.DOC's reasons.. :) It works just like get_key(), but you have to 'include get.e'. Not to hard, though... :)