Menu

#59 fix keypressed() function [r894]

Unstable_(example)
open
nobody
None
5
2017-09-15
2017-09-15
No

Hi,

Below is the example program from keypressed help page.
I added a single line, that prints the number of pressed keys.
Ttry to press multiple keys, using aditional keys as shift, alt or ctrl.
As you can see, the number of pressed keys is incorrect.

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
   print keypressed() #new line
end while

Also, you can do this:
1) run the same program and hold a direction key (eg. arrow up).
2) keep pressing arrow up while click with the mouse on editor window. Now release the key arrow up.
3) you can give back the focus to graph window or output text and press arrow left or arrow right... the ball will move always up because the key has been released ouside the graph window or output window and miss this release.

To avoid detecting keys as they are pressed because they are released when focus is lost, I reset the keys map when widget lose focus.

Respectfully,
Florin Oprea

Discussion


Log in to post a comment.