How to repeat behaviour CMD+arrowLeft (Home) and CMD+arrowRight (End) for fn+arrowLeft and fn+arrowRight as well. Please write code if existed another approach to move caret (cursor) to the begin or to the end of input field use combination of keys. I use MacOs.
- 36 - event.key for fn+arrowLeft
- 35 - event.key for fn+arrowRight
const handleKey = (e) => {
if (e.metaKey || e.altKey || e.ctrlKey) {
e.preventDefault();
}
if (e.key === 'Home') {
// code here
}
if (e.key === 'End') {
// code here
}
};
<input type="text" onkeydown="handleKey()">
As alternative way but doesn’t cover my need: Set keyboard caret position in html textbox
I assumed that good way but don’t know how use right KeyboardEvent object: how to set keycode value while triggering keypress event manually in pure javascript?