ForgeComponents
en

Components

j-Movement

jComponent 20 · jcomponent@20 component Example loaded with jComponent 20

This component captures basic keyboard keys like arrows, enter and esc.


Methods:

  • component.assign(ondown(key, e), [onunassign])

The assign method will clear previous assignments and applies new ones. We recommend calling the assign method to your elements when they are focused, or the user clicks on them.

Usage:

SETTER('movement/assign', function(key, e) {
	// @key {String}
	// @ {Event}
	switch (key) {
		case 'up':
		case 'down':
		case 'right':
		case 'left':
		case 'esc':
		case 'enter':
			break;
	}
});

Use it with <ui-component name="movement">. When the component is not loaded yet, jComponent downloads it on first use from the address in DEF.fallback (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

example.html
<ui-component name="movement"></ui-component>

<div class="block exec" data-exec="assignmovement" style="width:400px;height:400px;padding:20px;font-size:16px;border:2px solid #E0E0E0">
	Click here and press arrows/enter/esc: <b><ui-bind path="mykey" config="text;empty"></ui-bind></b>
</div>

<script>
	function assignmovement() {
		SETTER('movement/assign', function(key) {
			SET('mykey', key);
		});
	}
</script>