This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:keypressed [2016/05/12 20:11] admin created |
en:keypressed [2016/08/12 13:07] admin |
||
---|---|---|---|
Line 3: | Line 3: | ||
==== Format ==== | ==== Format ==== | ||
- | **keypressed** ( // | + | **keypressed** ( [[expressions|expression]] |
- | return | + | return |
==== Description ==== | ==== Description ==== | ||
Line 11: | Line 11: | ||
The KeyPressed function returns a true or false value if a key is currently pressed, or returns the number of keys that are currently being pressed. | The KeyPressed function returns a true or false value if a key is currently pressed, or returns the number of keys that are currently being pressed. | ||
+ | See the [[Key|key]] function for a list of common key codes or see [[http:// | ||
+ | ==== Example ==== | ||
+ | |||
+ | < | ||
+ | ar_down=16777237 | ||
+ | ar_up=16777235 | ||
+ | ar_left=16777234 | ||
+ | ar_right=16777236 | ||
+ | |||
+ | fastgraphics | ||
+ | x = 150 | ||
+ | y = 150 | ||
+ | color blue | ||
+ | |||
+ | print "use arrows to move the ball, space to exit" | ||
+ | |||
+ | while not keypressed(32) | ||
+ | if keypressed(ar_down) then y = y + 1 | ||
+ | if keypressed(ar_up) then y = y - 1 | ||
+ | if keypressed(ar_right) then x = x + 1 | ||
+ | if keypressed(ar_left) then x = x - 1 | ||
+ | # keep x and y in bounds 0-300 | ||
+ | x = (x + 300) % 300 | ||
+ | y = (y + 300) % 300 | ||
+ | # draw ball | ||
+ | clg | ||
+ | | ||
+ | | ||
+ | end while | ||
+ | </ | ||
==== See Also ==== | ==== See Also ==== | ||
- | {{page> | + | {{page> |
==== History ==== | ==== History ==== | ||
|1.99.99.26|New To Version| | |1.99.99.26|New To Version| |