User Tools

Site Tools


en:keypressed

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:keypressed [2016/08/12 13:07]
admin
en:keypressed [2020/02/28 10:46]
Line 1: Line 1:
-===== KeyPressed (Function) ====== 
  
-==== Format ==== 
- 
-**keypressed** ( [[expressions|expression]] ) 
- 
-return [[booleanexpressions|boolean_expression]] or [[integerexpressions|integer_expression]] 
- 
-==== Description ==== 
- 
-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.  Unlike the [[key|key]] function that clears the keyboard buffer, the KeyPressed function does not.  This allows for the creation of much more responsive games and other uses of the keyboard. 
- 
-See the [[Key|key]] function for a list of common key codes or see [[http://qt-project.org/doc/qt-4.8/qt.html#Key-enum|here]] for a complete list codes. 
- 
-==== Example ==== 
- 
-<code> 
-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 
-   circle x,y,10 
-   refresh 
-end while 
-</code> 
- 
-==== See Also ==== 
-{{page>en:start#Keyboard and User Input&noheader}} 
- 
-==== History ====  
-|1.99.99.26|New To Version|  
en/keypressed.txt ยท Last modified: 2020/02/28 10:46 (external edit)