Get_key

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu