JS to stop on-page keyboard controls

Discussion and feedback on Construct 2

Post » Wed Apr 24, 2013 4:34 am

I need to know whatever JS or lines of code Scirra puts into the Scirra arcade that prevents the keyboard from screwing with HTML5 games.

The fact that pressing space on the keyboard moves the user down the page is one reason I am getting 0/5 ratings on my game (remember, Newgrounds is a community full of little kids, and if things don't work they will give you 0 stars).

Space in my game is used to fire the ship. I have it mapped to a specific action, but this does not fix the problem because pressing space will still cause lots of people to scroll down the page (due to browser default settings).

Does anyone know how to fix this?
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Wed Apr 24, 2013 4:53 am

It's annoying every long HTML pages can be down the page by spacebar as default key, every browsers do.

I'm suggesting you should replace space bar to some letters as z,x,c,v,b

I don't remember if flash games used spacebar key.
B
95
S
25
G
20
Posts: 3,052
Reputation: 22,613

Post » Wed Apr 24, 2013 4:59 am

[QUOTE=Joannesalfa] It's annoying every long HTML pages can be down the page by spacebar as default key, every browsers do.

I'm suggesting you should replace space bar to some letters as z,x,c,v,b

I don't remember if flash games used spacebar key.[/QUOTE]

This is a workaround, not a solution. There is a solution out there.
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Wed Apr 24, 2013 5:10 am

Nevermind, I think I have found a solution. I've written a short blog post about it so I can refer to it later.

http://www.exeneva.com/2013/04/overriding-browser-default-keys-in-html5-games/
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Wed Apr 24, 2013 5:25 am

I didn't know about this useful solution, anyways thanks for sharing!
B
95
S
25
G
20
Posts: 3,052
Reputation: 22,613

Post » Wed Apr 24, 2013 11:36 am

I've built in the Arcade's workaround in to the runtime itself for the next beta, so hopefully that will fix it. If you view the source of the iframe page in the arcade, you should be able to see it calls preventDefault() and stopPropagation() on certain scrolling keys like space, arrow keys, etc.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Post » Wed Apr 24, 2013 12:20 pm

Thanks @Ashley, this is great to hear!
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194


Return to Construct 2 General

Who is online

Users browsing this forum: anty21ro, mystazsea and 13 guests