# j-Movement

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

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: dc36c810a5e106d8bf76743899b977eba91fef76dd6a1c75f9c2d99fc74b095a
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

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__:

```js
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.

```html 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>
```
