- Home /
How to check for pressed keys in WebGL?
Hi there,
In my project i check if a configured key is pressed during update as follows:
void Update() {
if(Input.GetButton("Player 1 left")) {
ExecuteAction();
}
}
When i "Build and Run" for WebGL and test the controls in Chrome (43.0.2357.134), the keypress is not recognized.
For my button configurations i use the "asdw" keys - this configuration works fine in the editor.
I already tried to set the focus on the canvas as follows, but still nothing fires:
http://gamejolt.com/community/forums/topics/unity5-webgl-game-doest-take-keyboard-focus/9253
http://forum.unity3d.com/threads/urgent-webgl-keyboards-event-not-working-when-in-a-iframe.299215/
Is this a known problem?
Thanks - Michael
Answer by angralon · Jul 19, 2015 at 01:25 AM
Nevermind, i used the wrong platform compilation constant, so my code was not even compiled.
Make sure to always use UNITY_WEBGL when working with WebGL ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220611231455im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Getting an "Uncaught SyntaxError" while trying to run WebGL game 1 Answer
WebGL - swiftshader - Unity 18.1, some scenes won't load 0 Answers
Someone knows how to disable multi-touch in WebGL? 0 Answers
I can't get webgl build running on Firefox Unity version 2021 1 Answer
WEB GL mouse position Input.mousePosition in chrome 0 Answers