html5 - H: HTML5 Events From Native Code
html5 - H: HTML5 Events From Native Code
16 documentation
html5 . h
T h e C++ APIs in html5 . h define t h e Emscripten low-level glue bindings to interact with
HTML5 events from native code.
Tip
T h e C++ APIs map closely to t h eir equivalent HTML5 JavaScript APIs. The HTML5
specifications listed below provide additional detailed reference “over and above” the
information provided in this document.
In addition, t h e Test/Example code can be reviewed to see how the code is used.
DOM Level 3 Events: Keyboard, Mouse, Mouse W h eel, Resize, Scroll, Focus .
Device Orientation Events for gyro and accelerometer .
Screen Orientation Events for portrait/landscape h andling .
Fullscreen Events for browser canvas fullscreen modes transitioning .
Pointer Lock Events for relative-mode mouse motion control .
Vibration API for mobile device h aptic vibration feedback control .
Page Visibility Events for power management control .
Touc h Events .
Gamepad API .
Beforeunload event .
WebGL context events
Table of Contents
Device motion
Orientation
Fullscreen
Pointerlock
Visibility
Touc h
Gamepad
Battery
Vibration
Page unload
WebGL context
CSS
Note
T h e Gamepad API is currently an exception, as only a polling API is available. For some
APIs, both an event-based and a polling-based model are exposed.
Registration functions
T h e typical format of registration functions is as follows (some methods may omit various
parameters):
EMSCRIPTEN_RESULT emscripten_set_some_callback(
const c h ar *target, // ID of t h e target HTML element.
void *userData, // User-defined data to be passed to t h e callback.
EM_BOOL useCapture, // W h ether or not to use capture.
em_someevent_callback_func callback // Callback function.
);
T h e target parameter is the ID of the HTML element to which the callback registration is to
be applied. This field has the following special meanings:
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callback… 2/55
11/28/2018 0 or NULL : A default element html5.h
is c h —osen
Emscripten 1.38.16 documentation
automatically based on the event type, which
should be reasonable most of the time.
#window : T h e event listener is applied to t h e JavaScript window object.
#document : T h e event listener is applied to t h e JavaScript document object.
#screen : T h e event listener is applied to t h e JavaScript window.screen object.
#canvas : T h e event listener is applied to the Emscripten default WebGL canvas
element.
Any ot h er string without a leading hash “#” sign: The event listener is applied to the
element on the page with the given ID.
Most functions return t h e result using t h e type EMSCRIPTEN_RESULT . Zero and positive values
denote success. Negative values signal failure. None of the functions fail or abort by throwing a
JavaScript or C++ exception. If a particular browser does not support the given feature, the
value EMSCRIPTEN_RESULT_NOT_SUPPORTED will be returned at the time the callback is registered.
Callback functions
W h en t h e event occurs t h e callback is invoked wit h the relevant event “type” (for
example EMSCRIPTEN_EVENT_CLICK ), a struct containing the details of the event that occurred,
and the userData that was originally passed to the registration function. The general format of
the callback function is:
Calling a registration function wit h a null pointer for t h e callback causes a de-registration
of t h at callback from t h e given target element. All event h andlers are also automatically
unregistered w h en t h e C exit() function is invoked during the atexit handler pass.
Either use the function emscripten_set_main_loop() or set Module.noExitRuntime = true; to
make sure that leaving main() will not immediately cause an exit() and clean up the event
handlers.
W h ile the functions can be called anywhere, the actual “requests” can only be raised inside
the handler for a user-generated event (for example a key, mouse or touch press/release).
W h en porting code, it may be difficult to ensure t h at the functions are called inside
appropriate event handlers (so that the requests are raised immediately). As a convenience,
developers can set deferUntilInEventHandler=true to automatically defer insecure requests
until the user next presses a keyboard or mouse button. This simplifies porting, but often results
in a poorer user experience. For example, the user must click once on the canvas to hide the
pointer or transition to full screen.
W h ere possible, t h e functions should only be called inside appropriate event handlers.
Setting deferUntilInEventHandler=false causes the functions to abort with an error if the
request is refused due to a security restriction: this is a useful mechanism for discovering
instances where the functions are called outside the handler for a user-generated event.
Test/Example code
test_ html5 .c
test_ html5 _fullscreen.c
test_ html5 _mouse.c
General types
EM_BOOL
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callback… 4/55
11/28/2018T h is is t h e Emscripten type for html5.h
a bool— .Emscripten
Possible1.38.16 documentation
values:
EM_TRUE
EM_FALSE
EM_UTF8
T h is is t h e Emscripten type for a UTF8 string (maps to a char ). This is used for node
names, element ids, etc.
EMSCRIPTEN_RESULT
T h is type is used to return the result of most functions in this API. Zero and positive values
denote success, while negative values signal failure. Possible values are listed below.
EMSCRIPTEN_RESULT_SUCCESS
T h e operation succeeded.
EMSCRIPTEN_RESULT_DEFERRED
T h e requested operation cannot be completed now for web security reasons, and has
been deferred for completion in the next event handler.
EMSCRIPTEN_RESULT_NOT_SUPPORTED
T h e given operation is not supported by this browser or the target element. This value
will be returned at the time the callback is registered if the operation is not supported.
EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED
T h e requested operation could not be completed now for web security reasons. It
failed because the user requested the operation not be deferred.
EMSCRIPTEN_RESULT_INVALID_TARGET
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callback… 5/55
11/28/2018 T h e operation failed becausehtml5.h — Emscripten
the specified 1.38.16
target documentation
element is invalid.
EMSCRIPTEN_RESULT_UNKNOWN_TARGET
T h e operation failed because the specified target element was not found.
EMSCRIPTEN_RESULT_INVALID_PARAM
EMSCRIPTEN_RESULT_FAILED
EMSCRIPTEN_RESULT_NO_DATA
Keys
De nes
DOM_KEY_LOCATION
DOM_KEY_LOCATION_NUMPAD
Struct
EmscriptenKeyboardEvent
Note t h at since t h e DOM Level 3 Events spec is very recent at the time of writing
(2014-03), uniform support for the different fields in the spec is still in flux. Be sure to check
the results in multiple browsers. See the unmerged pull request #2222 for an example of
how to interpret the legacy key events.
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callback… 6/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
EM_UTF8 key
EM_UTF8 code
A string t h at identifies the physical key being pressed. The value is not affected by the
current keyboard layout or modifier state, so a particular key will always return the same
value.
EM_BOOL repeat
EM_UTF8 locale
A locale string indicating t h e configured keyboard locale. This may be an empty string
if the browser or device doesn’t know the keyboard’s locale.
EM_UTF8 c h arValue
T h e following fields are values from previous versions of t h e DOM key events
specifications. See t h e character representation of the key . T h is is the field char
from the docs, but renamed to charValue to avoid a C reserved word.
Warning
Warning
T h is attribute is deprecated, you s h ould use the field key instead, if available.
Warning
T h is attribute is deprecated, you s h ould use the field key instead, if available.
Warning
Callback functions
em_key_callback_func
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callback… 8/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: eventType (int) – T h e type of key event .
keyEvent (const EmscriptenKeyboardEvent*) – Information about t h e key
event that occurred.
userData (void*) – T h e userData originally passed to the registration
function.
Functions
Mouse
De nes
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callback… 9/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
EMSCRIPTEN_EVENT_CLICK EMSCRIPTEN_EVENT_MOUSEDOWN EMSCRIPTEN_EVENT_MOUSEUP
EMSCRIPTEN_EVENT_MOUSELEAVE
Struct
EmscriptenMouseEvent
double timestamp;
0 : Left button
1 : Middle button (if present)
2 : Rig h t button
A bitmask t h at indicates which combinations of mouse buttons were being held down
at the time of the event.
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 10/55
11/28/2018 If pointer lock is active, t h esehtml5.h — Emscripten
two extra 1.38.16
fields give documentation
relative mouse movement since the
last event.
T h ese fields give the mouse coordinates mapped relative to the coordinate space of
the target DOM element receiving the input events (Emscripten-specific extension).
T h ese fields give the mouse coordinates mapped to the Emscripten canvas client area
(Emscripten-specific extension).
long padding
Note
Callback functions
em_mouse_callback_func
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 11/55
Functions
11/28/2018 html5.h — Emscripten 1.38.16 documentation
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 12/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: mouseState (EmscriptenMouseEvent*) – T h e most recently received
mouse event state.
W h eel
De nes
EMSCRIPTEN_EVENT_W H EEL
DOM_DELTA_PIXEL
DOM_DELTA_LINE
T h e units of measurement for t h e delta must be individual lines of text (from spec ).
DOM_DELTA_PAGE
T h e units of measurement for t h e delta must be pages, either defined as a single screen
or as a demarcated page (from spec ).
Struct
EmscriptenW h eelEvent
EmscriptenMouseEvent mouse
Movement of t h e wheel on each of the axis. Note that these values may be fractional,
so you should avoid simply casting them to integer, or it might result in scroll values of 0.
The positive Y scroll direction is when scrolling the page downwards (page CSS pixel +Y
direction), which corresponds to scrolling the mouse wheel downwards (away from the
screen) on Windows, Linux, and also on OSX when the ‘natural scroll’ option is disabled.
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 13/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
unsigned long deltaMode
One of t h e DOM_DELTA_ values that indicates the units of measurement for the delta
values.
Callback functions
em_w h eel_callback_func
Functions
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 14/55
11/28/2018
Return type: EMSCRIPTEN_RESULT html5.h — Emscripten 1.38.16 documentation
UI
De nes
EMSCRIPTEN_EVENT_RESIZE EMSCRIPTEN_EVENT_SCROLL
Emscripten UI events.
Struct
EmscriptenUiEvent
T h e event structure passed in DOM element UIEvent events: resize and scroll .
long detail
Callback functions
em_ui_callback_func
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 15/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: eventType (int) – T h e type of UI event ( EMSCRIPTEN_EVENT_RESIZE ).
uiEvent (const EmscriptenUiEvent*) – Information about t h e UI event that
occurred.
userData (void*) – T h e userData originally passed to the registration
function.
Functions
Registers a callback function for receiving DOM element resize and scroll events.
Note
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 16/55
Focus
11/28/2018 html5.h — Emscripten 1.38.16 documentation
De nes
EMSCRIPTEN_EVENT_FOCUSOUT
Struct
EmscriptenFocusEvent
T h e event structure passed in DOM element blur , focus , focusin and focusout
events.
EM_UTF8 nodeName
EM_UTF8 id
Callback functions
em_focus_callback_func
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 17/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Returns: true (non zero) to indicate t h at t h e event was consumed by the
callback handler.
Functions
Registers a callback function for receiving DOM element blur , focus , focusin and
focusout events.
Device orientation
De nes
EMSCRIPTEN_EVENT_DEVICEORIENTATION
Struct
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 18/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
EmscriptenDeviceOrientationEvent
double timestamp
EM_BOOL absolute
If false , t h e orientation is only relative to some other base orientation, not to the fixed
coordinate frame.
Callback functions
em_deviceorientation_callback_func
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 19/55
11/28/2018Function html5.h
pointer for t h e orientation — Emscripten
event callback 1.38.16 documentation
functions , defined as:
Functions
EMSCRIPTEN_RESULT
emscripten_get_deviceorientation_status (EmscriptenDeviceOrientationEvent *orientationState)
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 20/55
11/28/2018Note html5.h
t h at for t h is function call to — Emscripten
succeed, 1.38.16 documentation
emscripten_set_deviceorientation_callback()
must have first been called with one of the mouse event types and a non-zero callback
function pointer to enable the deviceorientation state capture.
Device motion
De nes
EMSCRIPTEN_EVENT_DEVICEMOTION
Struct
EmscriptenDeviceMotionEvent
double timestamp
double accelerationIncludingGravityZ
Callback functions
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 21/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
em_devicemotion_callback_func
Functions
EMSCRIPTEN_RESULT
emscripten_get_devicemotion_status (EmscriptenDeviceMotionEvent *motionState)
Orientation
De nes
EMSCRIPTEN_EVENT_ORIENTATIONC H ANGE
EMSCRIPTEN_ORIENTATION_PORTRAIT_PRIMARY
EMSCRIPTEN_ORIENTATION_PORTRAIT_SECONDARY
EMSCRIPTEN_ORIENTATION_LANDSCAPE_PRIMARY
EMSCRIPTEN_ORIENTATION_LANDSCAPE_SECONDARY
Struct
EmscriptenOrientationC h angeEvent
int orientationIndex
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 23/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
int orientationAngle
Callback functions
em_orientationc h ange_callback_func
Functions
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 24/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: userData (void*) – User-defined data to be passed to t h e callback (opaque
to the API).
useCapture (EM_BOOL) – Set true to use capture.
callback (em_orientationc h ange_callback_func) – A callback function. T h
e function is called wit h the type of event, information about the event, and
user data passed from this registration function. The callback should return
true if the event is consumed.
Fullscreen
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 25/55
De nes
11/28/2018 html5.h — Emscripten 1.38.16 documentation
EMSCRIPTEN_EVENT_FULLSCREENC H ANGE
EMSCRIPTEN_FULLSCREEN_SCALE
An enum-like type w h ic h specifies h ow the Emscripten runtime should treat the CSS
size of the target element when displaying it in fullscreen mode via calls to functions
emscripten_request_fullscreen_strategy() and emscripten_enter_soft_fullscreen() .
EMSCRIPTEN_FULLSCREEN_SCALE_DEFAULT
EMSCRIPTEN_FULLSCREEN_SCALE_STRETC H
Specifies t h at the Emscripten runtime should explicitly stretch the CSS size of the target
element to cover the whole screen when transitioning to fullscreen mode. This will change
the aspect ratio of the displayed content.
EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT
Specifies t h at t h e Emscripten runtime should explicitly scale the CSS size of the target
element to cover the whole screen, while adding either vertical or horizontal black letterbox
padding to preserve the aspect ratio of the content. The aspect ratio that is used here is the
render target size of the canvas element. To change the desired aspect ratio, call
emscripten_set_canvas_size() before entering fullscreen mode.
EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 26/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE
Specifies t h at the Emscripten runtime should not do any changes to the render target
resolution of the target canvas element that is displayed in fullscreen mode. Use this mode
when your application is set up to render to a single fixed resolution that cannot be changed
under any condition.
EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF
Specifies t h at t h e Emscripten runtime s h ould resize the render target of the canvas
element to match 1:1 with the CSS size of the element in fullscreen mode. On high DPI
displays (window.devicePixelRatio > 1), the CSS size is not the same as the physical screen
resolution of the device. Call emscripten_get_device_pixel_ratio() to obtain the pixel ratio
between CSS pixels and actual device pixels of the screen. Use this mode when you want
to render to a pixel resolution that is DPI-independent.
EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_ H IDEF
Specifies t h at the Emscripten runtime should resize the canvas render target size to
match 1:1 with the physical screen resolution on the device. This corresponds to high
definition displays on retina iOS and other mobile and desktop devices with high DPI. Use
this mode to match and render 1:1 to the native display resolution.
EMSCRIPTEN_FULLSCREEN_FILTERING
An enum-like type t h at specifies what kind of image filtering algorithm to apply to the
element when it is presented in fullscreen mode.
EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT
Specifies t h at the image filtering mode should not be changed from the existing setting in
the CSS style.
EMSCRIPTEN_FULLSCREEN_FILTERING_NEAREST
Applies a CSS style to t h e element that displays the content using a nearest-neighbor
image filtering algorithm in fullscreen mode.
EMSCRIPTEN_FULLSCREEN_FILTERING_BILINEAR
Applies a CSS style to t h e element that displays the content using a bilinear image filtering
algorithm in fullscreen mode. This is the default browser behavior.
Struct
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 27/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
EmscriptenFullscreenC h angeEvent
EM_BOOL isFullscreen
EM_BOOL fullscreenEnabled
EM_UTF8 nodeName
EM_UTF8 id
EmscriptenFullscreenStrategy
EMSCRIPTEN_FULLSCREEN_SCALE scaleMode
Specifies t h e rule how the CSS size (the displayed size) of the target element is
resized when displayed in fullscreen mode.
EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE canvasResolutionScaleMode
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 28/55
11/28/2018 html5.h
Specifies h ow the render target size—(the
Emscripten
pixel 1.38.16 documentation
resolution) of the target element is
adjusted when displayed in fullscreen mode.
EMSCRIPTEN_FULLSCREEN_FILTERING filteringMode
em_canvasresized_callback_func canvasResizedCallback
void * canvasResizedCallbackUserData
Stores a custom data field w h ich will be passed to all calls to the user-provided
callback function.
Callback functions
em_fullscreenc h ange_callback_func
Functions
Note
T h is function can be called anyw h ere, but for web security reasons its associated
request can only be raised inside t h e event handler for a user-generated event (for
example a key, mouse or touch press/release). This has implications for porting and the
value of deferUntilInEventHandler — see Functions affected by web security for more
information.
Note
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 30/55
11/28/2018 html5.h — Emscripten
T h is function only performs a fullscreen request 1.38.16 documentation
wit h out c h anging any parameters
of t h e DOM element that is to be displayed in fullscreen mode. At the time of writing,
there are differences in how browsers present elements in fullscreen mode. For more
information, read the discussion at https://github.com/kripken/emscripten/issues/2556 .
To display an element in fullscreen mode in a way that is consistent across browsers,
prefer calling the function emscripten_request_fullscreen_strategy() instead. This
function is best called only in scenarios where the preconfigured presets defined by
emscripten_request_fullscreen_strategy() conflict with the developer’s use case in
some way.
Requests t h e given target element to transition to full screen mode, using a custom
presentation mode for t h e element. This function is otherwise the same as
emscripten_request_fullscreen() , but this function adds options to control how resizing and
aspect ratio, and ensures that the behavior is consistent across browsers.
Note
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 31/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
EMSCRIPTEN_RESULT emscripten_exit_fullscreen (void)
Do not call t h is function to attempt to return to windowed browsing mode from a soft
fullscreen mode, or vice versa.
Enters a “soft” fullscreen mode, w h ere the given target element is displayed in the whole
client area of the page and all other elements are hidden, but does not actually request
fullscreen mode for the browser. This function is useful in cases where the actual Fullscreen
API is not desirable or needed, for example in packaged apps for Firefox OS, where
applications essentially already cover the whole screen.
Pressing t h e esc button does not automatically exit t h e soft fullscreen mode. To return to
windowed presentation mode, manually call the function
emscripten_exit_soft_fullscreen() .
EMSCRIPTEN_RESULT emscripten_exit_soft_fullscreen ()
Returns back to windowed browsing mode from a soft fullscreen mode. Do not call t h is
function to attempt to return to windowed browsing mode from a real fullscreen mode, or
vice versa.
Pointerlock
De nes
EMSCRIPTEN_EVENT_POINTERLOCKC H ANGE
EMSCRIPTEN_EVENT_POINTERLOCKERROR
Struct
EmscriptenPointerlockC h angeEvent
Specifies w h ether an element on the browser page currently has pointer lock enabled.
EM_UTF8 nodeName
T h e nodeName of the target HTML Element that has the pointer lock active.
EM_UTF8 id
T h e ID of the target HTML element that has the pointer lock active.
Callback functions
em_pointerlockc h ange_callback_func
em_pointerlockerror_callback_func
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 33/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: eventType (int) – T h e type of pointerlockerror event
( EMSCRIPTEN_EVENT_POINTERLOCKERROR ).
void* reserved (const) – Reserved for future use; pass in 0.
userData (void*) – T h e userData originally passed to the registration
function.
Functions
Pointer lock h ides t h e mouse cursor and exclusively gives the target element relative
mouse movement events via the mousemove event.
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 34/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: target (const c h ar*) – Target H TML element id.
userData (void*) – User-defined data to be passed to t h e callback (opaque
to the API).
useCapture (EM_BOOL) – Set true to use capture.
callback (em_pointerlockerror_callback_func) – A callback function. T h e
function is called wit h the type of event, information about the event, and
user data passed from this registration function. The callback should return
true if the event is consumed.
Note
T h is function can be called anyw h ere, but for web security reasons its associated
request can only be raised inside t h e event handler for a user-generated event (for
example a key, mouse or touch press/release). This has implications for porting and the
value of deferUntilInEventHandler — see Functions affected by web security for more
information.
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 35/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: target (const c h ar*) – Target H TML element id.
deferUntilInEvent H andler (EM_BOOL) – If true requests made outside of
a user-generated event h andler are automatically deferred until t h e user
next presses a keyboard or mouse button. If false the request will fail if
called outside of a user-generated event handler.
Exits pointer lock state and restores t h e mouse cursor to be visible again.
Visibility
De nes
EMSCRIPTEN_EVENT_VISIBILITYC H ANGE
EMSCRIPTEN_VISIBILITY_ H IDDEN
EMSCRIPTEN_VISIBILITY_VISIBLE
EMSCRIPTEN_VISIBILITY_PRERENDER
EMSCRIPTEN_VISIBILITY_UNLOADED
T h e document is to be unloaded .
Struct
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 36/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
EmscriptenVisibilityC h angeEvent
EM_BOOL h idden
int visibilityState
Callback functions
em_visibilityc h ange_callback_func
Functions
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 37/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: userData (void*) – User-defined data to be passed to t h e callback (opaque
to the API).
useCapture (EM_BOOL) – Set true to use capture.
callback (em_visibilityc h ange_callback_func) – A callback function. T h e
function is called wit h the type of event, information about the event, and
user data passed from this registration function. The callback should return
true if the event is consumed.
Touc h
De nes
EMSCRIPTEN_EVENT_TOUC H CANCEL
Struct
EmscriptenTouc h Point
long identifier
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 38/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
long screenX long screenY
T h e touch coordinate relative to the viewport, in pixels, and including any scroll offset.
EM_BOOL onTarget
Specifies w h ether this touch point is still above the original target on which it was
initially pressed.
T h ese fields give the touch coordinates mapped relative to the coordinate space of the
target DOM element receiving the input events (Emscripten-specific extension).
EmscriptenTouc h Event
int numTouc h es
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 39/55
Callback functions
11/28/2018 html5.h — Emscripten 1.38.16 documentation
em_touc h _callback_func
typedef EM_BOOL (*em_touc h _callback_func)(int eventType, const EmscriptenTouc h Event *touc h Event,
void *userData);
Functions
Registers a callback function for receiving touc h events : touc h start , touc h end ,
touc h move and touc h cancel .
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 40/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: target (const c h ar*) – Target H TML element id.
userData (void*) – User-defined data to be passed to t h e callback (opaque
to the API).
useCapture (EM_BOOL) – Set true to use capture.
callback (em_touc h _callback_func) – A callback function. T h e function is
called wit h the type of event, information about the event, and user data
passed from this registration function. The callback should return true if the
event is consumed.
Gamepad
De nes
EMSCRIPTEN_EVENT_GAMEPADCONNECTED EMSCRIPTEN_EVENT_GAMEPADDISCONNECTED
Struct
EmscriptenGamepadEvent
double timestamp
int numAxes
int numButtons
double axis[64]
double analogButton[64]
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 41/55
11/28/2018 html5.h
T h e analog state of the gamepad — Emscripten
buttons, 1.38.16
in the rangedocumentation
[0, 1].
EM_BOOL digitalButton[64]
EM_BOOL connected
long index
EM_UTF8 id
An ID for t h e brand or style of the connected gamepad device. Typically, this will
include the USB vendor and a product ID.
EM_UTF8 mapping
Callback functions
em_gamepad_callback_func
Functions
Note
Note
Gamepad API uses an array of gamepad state objects to return t h e state of each
device. The devices are identified via the index they are present in in this array. Because
of that, if one first connects gamepad A, then gamepad B, and then disconnects
gamepad A, the gamepad B shall not take the place of gamepad A, so in this scenario,
this function will still keep returning two for the count of connected gamepads, even
though gamepad A is no longer present. To find the actual number of connected
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 43/55
11/28/2018 html5.h — Emscripten
gamepads, listen for the gamepadconnected 1.38.16 documentation
and gamepaddisconnected events.
Consider the return value of this function as the largest value (-1) that can be passed to
the function emscripten_get_gamepad_status().
Parameters: index (int) – T h e index of t h e gamepad to check (in the array of connected
gamepads ).
gamepadState (EmscriptenGamepadEvent*) – T h e most recently received
gamepad state.
Battery
De nes
Struct
EmscriptenBatteryEvent
double c h argingTime
Time remaining until t h e battery is empty and the system will be suspended (seconds).
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 44/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
double level
EM_BOOL c h arging;
Callback functions
em_battery_callback_func
Functions
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 45/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: userData (void*) – User-defined data to be passed to t h e callback (opaque
to the API).
callback (em_battery_callback_func) – A callback function. T h e function is
called wit h the type of event, information about the event, and user data
passed from this registration function. The callback should return true if the
event is consumed.
Vibration
Functions
Parameters: msecs (int) – T h e amount of time for which the vibration is required
(milliseconds).
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 46/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: msecsArray (int*) – An array of timing entries [on, off, on, off, on, off, …] w h
ere every second one specifies a duration of vibration, and every other one
specifies a duration of silence.
numEntries (int) – T h e number of integers in t h e array msecsArray .
Page unload
De nes
EMSCRIPTEN_EVENT_BEFOREUNLOAD
Callback functions
em_beforeunload_callback
Functions
WebGL context
De nes
EMSCRIPTEN_EVENT_WEBGLCONTEXTLOST EMSCRIPTEN_EVENT_WEBGLCONTEXTRESTORED
EMSCRIPTEN_WEBGL_CONTEXT_ H ANDLE
Struct
EmscriptenWebGLContextAttributes
EM_BOOL alp h a
If true , request an alp h a c h annel for the context. If you create an alpha channel,
you can blend the canvas rendering with the underlying web page contents. Default
value: true .
EM_BOOL dept h
If true , request a dept h buffer of at least 16 bits. If false , no dept h buffer will be
initialized. Default value: true .
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 48/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
EM_BOOL stencil
If true , request a stencil buffer of at least 8 bits. If false , no stencil buffer will be
initialized. Default value: false .
EM_BOOL antialias
EM_BOOL premultipliedAlp h a
EM_BOOL preserveDrawingBuffer
EM_BOOL failIfMajorPerformanceCaveat
EM_BOOL enableExtensionsByDefault
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 49/55
11/28/2018 If true , all GLES2-compatiblehtml5.h — Emscripten 1.38.16 documentation
non-performance-impacting WebGL extensions will
automatically be enabled for you after t h e context h as been created. If false , no
extensions are enabled by default, and you need to manually call
emscripten_webgl_enable_extension() to enable each extension that you want to use.
Default value: true .
EM_BOOL explicitSwapControl
EM_BOOL renderViaOffscreenBackBuffer
Callback functions
em_webgl_context_callback
Function pointer for t h e WebGL Context event callback functions , defined as:
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 50/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
typedef EM_BOOL (*em_webgl_context_callback)(int eventType, const void *reserved, void *userData);
Functions
Queries t h e given canvas element for whether its WebGL context is in a lost state.
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 51/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Returns: true if t h e WebGL context is in a lost state.
Note
Parameters: target (const c h ar*) – T h e DOM canvas element in w h ich to initialize the
WebGL context. If 0 is passed, the element specified by Module.canvas will be
used.
attributes (const EmscriptenWebGLContextAttributes*) – T h e attributes of
the requested context version.
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 52/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
EMSCRIPTEN_RESULT emscripten_webgl_make_context_current (EMSCRIPTEN_WEBGL_CONTEXT_
H ANDLE context)
Activates t h e given WebGL context for rendering. After calling t h is function, all OpenGL
functions ( glBindBuffer() , glDrawArrays() , etc.) can be applied to the given GL context.
EMSCRIPTEN_RESULT emscripten_webgl_commit_frame ()
EMSCRIPTEN_RESULT
emscripten_webgl_get_drawing_buffer_size (EMSCRIPTEN_WEBGL_CONTEXT_ H ANDLE context,
int *widt h , int * h eight)
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 53/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Returns: EMSCRIPTEN_RESULT_SUCCESS , or one of t h e other result values.
Deletes t h e given WebGL context. If that context was active, then the no context is set to
active.
CSS
Functions
Resizes t h e CSS widt h and height of the element specified by target on the
Emscripten web page.
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 54/55
11/28/2018 html5.h — Emscripten 1.38.16 documentation
Parameters: target (const c h ar*) – Element to resize. If 0 is passed, t h e element
specified by Module.canvas will be used.
widt h (double) – New widt h of the element.
h eight (double) – New h eight of the element.
Gets t h e current CSS widt h and height of the element specified by target .
Parameters: target (const c h ar*) – Element to get size of. If 0 is passed, t h e element
specified by Module.canvas will be used.
widt h (double*) – Widt h of the element.
h eight (double*) – H eight of the element.
Previous Next
Report Bug Licensing Contributing Mailing list Wiki Release notes Blogs Contact
https://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html?highlight=html5%20h#c.em_fullscreenchange_callbac… 55/55