KeyPressed event

Trying to understand what is going on with keypressed event.

Rectangle has a keypressed event but I read somewhere else on the forum that it doesn’t work because Rectangle can’t get focus. Why does keypressed event show up if it can’t be used?

Could not get keypressed event to work in WebButton.

Canvas doesn’t have a keypressed event but it seems like it should.

Finally got the keypressed event to work using a textfield but it is a little cumbersome to use for what I am doing. I am using keypressed event to register up and down arrow keys, not text input.

Not sure textfield is the best way to do this. Any suggestions?

I believe the KeyPressed event works on the WebPage. However, if a control has the focus that can accept text the control will handle the key press and not the webpage so you’ll most likely have to add some special handling in the controls too.

Ok, I tried KeyPressed for page and it works fine if I set a timer to give it focus every half second.

Seems to work a little better than textfield. With textfield, it occasionally stops working for some weird reason (even with the setfocus timer and clearing the textfield every time it gets a keypressed event).

Gotta figure out how to repeat key next.

Keep in mind that a period of 1/2 second will likely fail on the web as latencies are sometimes longer than that.

Interesting you should mention that.,

It turns out my setfocus to the webpage isn’t working at all (the timer works, the setfocus just doesn’t do anything). I set it to setfocus every 3, 6, 10 seconds, still nothing. I have a button on the page and I can press it and it has focus ring and the setfocus to the webpage doesn’t do anything. I can left-click inside the page and it returns focus but that’s not going to be good enough.

What am I doing wrong? Let me know if you need me to work up a sample that demonstrates the problem (usually the process of doing this helps me find the problem anyway). The page just has a canvas on it and three buttons.

I can setfocus to a button but not a webpage.

Unfortunately, the keypressed event in a button isn’t working.

Any suggestions?

I went back to using a textfield. Seems to work okay and focus can be set.

Unfortunately, the page occasionally stops responding to keypresses (arrow keys). I will try to work up an example over the weekend.