KeyUp (on Canvas)

Is possible that KeyUp event is received later if KeyDown has been kept pushed longer?
And is there a way to avoid it? Is it normal?

The case is:

  • when KeyDown, a boolean is made true, and refresh(), then the canvas paint even draw something
case "p"
  ShowPath=true
  Refresh
  • when KeyUp, the boolean is made false and refresh()
case "p"
  ShowPath=false
  Refresh

This works ok, just refresh() later.

https://documentation.xojo.com/api/user_interface/desktop/desktopcanvas.html#desktopcanvas-refresh

use System.DebugLog CurrentMethodName

if you hold a key it looks like:
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyDown
Window1.Canvas1.KeyUp

try Refresh with argument immediately = true at KeyUp

you could also use

if ShowPath=false
  ShowPath=true
  Refresh
endif

if ShowPath=false
ShowPath=true
Refresh
endif

This simple check helped a lot, thanks

1 Like

After reading the documentation I would write:
Refresh(True)

to fet an immediate refresh. But if this is OK for you… it is for me.