phaser/src/device/Input.js

75 lines
2 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2020-01-15 12:07:09 +00:00
* @copyright 2020 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-02-12 16:01:20 +00:00
*/
var Browser = require('./Browser');
/**
* Determines the input support of the browser running this Phaser Game instance.
* These values are read-only and populated during the boot sequence of the game.
* They are then referenced by internal game systems and are available for you to access
* via `this.sys.game.device.input` from within any Scene.
*
2018-03-28 14:04:09 +00:00
* @typedef {object} Phaser.Device.Input
* @since 3.0.0
*
* @property {?string} wheelType - The newest type of Wheel/Scroll event supported: 'wheel', 'mousewheel', 'DOMMouseScroll'
* @property {boolean} gamepads - Is navigator.getGamepads available?
* @property {boolean} mspointer - Is mspointer available?
* @property {boolean} touch - Is touch available?
*/
2016-11-25 04:00:15 +00:00
var Input = {
gamepads: false,
2016-11-25 04:00:15 +00:00
mspointer: false,
touch: false,
wheelEvent: null
2016-11-25 04:00:15 +00:00
};
function init ()
2016-11-25 04:00:15 +00:00
{
if (typeof importScripts === 'function')
{
return Input;
}
2017-09-09 02:28:38 +00:00
if ('ontouchstart' in document.documentElement || (navigator.maxTouchPoints && navigator.maxTouchPoints >= 1))
2016-11-25 04:00:15 +00:00
{
Input.touch = true;
}
2017-09-09 02:28:38 +00:00
if (navigator.msPointerEnabled || navigator.pointerEnabled)
2016-11-25 04:00:15 +00:00
{
Input.mspointer = true;
}
2017-09-09 02:28:38 +00:00
if (navigator.getGamepads)
{
Input.gamepads = true;
}
2019-02-15 10:38:57 +00:00
// See https://developer.mozilla.org/en-US/docs/Web/Events/wheel
if ('onwheel' in window || (Browser.ie && 'WheelEvent' in window))
2016-11-25 04:00:15 +00:00
{
2019-02-15 10:38:57 +00:00
// DOM3 Wheel Event: FF 17+, IE 9+, Chrome 31+, Safari 7+
Input.wheelEvent = 'wheel';
}
else if ('onmousewheel' in window)
{
// Non-FF legacy: IE 6-9, Chrome 1-31, Safari 5-7.
Input.wheelEvent = 'mousewheel';
}
else if (Browser.firefox && 'MouseScrollEvent' in window)
{
// FF prior to 17. This should probably be scrubbed.
Input.wheelEvent = 'DOMMouseScroll';
2016-11-25 04:00:15 +00:00
}
return Input;
}
module.exports = init();