1. putitng info from keyboard
- Posted by alan123 Feb 17, 2009
- 963 views
I am new to this but what I want to do like I did in basic to start with is to be able to input info useing the keyboard.I have look and havn't seen an example of it.I think it could be something like getkey.but what would you put the answer in
2. Re: putitng info from keyboard
- Posted by ghaberek (admin) Feb 17, 2009
- 1009 views
sequence input input = prompt_string( "Please enter your input: " ) printf( 1, "Your input was: \"%s\"\n", {input} )
-Greg
3. Re: putitng info from keyboard
- Posted by Andy Feb 17, 2009
- 975 views
Another easy example would be.
include get.e constant ESC = 27 integer key key = get_key() while 1 do if key = ESC then exit end if end while
This will end the program when you press ESC. Check the key.bat for list of keycodes.
4. Re: putitng info from keyboard
- Posted by ghaberek (admin) Feb 17, 2009
- 953 views
Another easy example would be.
code
This will end the program when you press ESC. Check the key.bat for list of keycodes.
That won't do anything since it only calls get_key() once.
include get.e constant ESC = 27 integer key while 1 do key = get_key() -- moved inside the loop if key = ESC then exit end if end while
That's better.
-Greg
5. Re: putitng info from keyboard
- Posted by ghaberek (admin) Feb 17, 2009
- 964 views
You could also use wait_key() instead of get_key() in that example, which would wait gracefully rather than polling continuously.
-Greg
6. Re: putitng info from keyboard
- Posted by Andy Feb 17, 2009
- 1008 views
You could also use wait_key() instead of get_key() in that example, which would wait gracefully rather than polling continuously.
-Greg
Ah that's right, Thanks for catching my error.
7. Re: putitng info from keyboard
- Posted by fred Feb 19, 2009
- 964 views
is there a way to set a time limit or have it randomised
8. Re: putitng info from keyboard
- Posted by fred Feb 19, 2009
- 920 views
so is the sentence saved in key
9. Re: putitng info from keyboard
- Posted by ghaberek (admin) Feb 19, 2009
- 922 views
is there a way to set a time limit
You'd have to write your own input function that uses get_key() to watch for keyboard and collect it in a sequence, while also monitoring the time passed since it started monitoring. Then when the time passed a certain point, it would exit its loop and continue on.
or have it randomised
Or have what randomized? The input from the user? The time limit?
so is the sentence saved in key
get_key() and wait_key() only return the key pressed:
integer key key = wait_key() printf( 1, "%s\n", key )
So if I press the 'K' key, that would simply output:
K
-Greg