Add blocks for detecting mobile devices/touchscreen
-
I have somewhat of a solution to this by regex checking if the user agent contains “Android” or “Mobi” or some other stuff (to see if a user is using mobile), but JavaScript provides other methods like checking navigator.maxTouchPoints (to check for touchscreen) and all.
I want to use this to detect if the user is using mobile/touchscreen, and then provide joysticks for my 3D scene. I propose two new blocks:
- Sensing reporter block: (is touchscreen?) , uses navigator.maxTouchPoints and checks if it is above 0. If it is above 0 then there’s touchscreen, but if it isn’t then its a computer.
- Sensing reporter block: (is mobile?) , is more general, and would generally mean touchscreen and no keyboard. This would be most useful for detecting then adding joysticks in my code.
My current method for seeing is the user agent is mobile is also kind of frowned upon and doesn’t always work because users can enable “Desktop mode” in their mobile browsers which would make the game unplayable. There’s also like different browsers too
-
@jeffreyrb03-gmail I dont think you can directly detect touchscreen but you can definetly detect if its mobile (like you said with user agent) because devices might not broadcast touch screen support, though you could detect as soon as a touch is detected, though I think you have to detect touch differently than mouse clicks (pretty sure) so you can even detect if touchscreen was last used
-
@tyller_ yeah true, ontouchstart events and navigator.maxTouchPoints do mean touchscreen tho
-
@jeffreyrb03-gmail yeah but with some touchscreen it allows for mouse and touchscreen, so maybe header blocks for when touchscreen started and when non touchscreen started? or just a booolean for if touchscreen is in use (whether last press was mouse or touchscreen) then manually detect changes and run scripts (toggling joysticks etc)