Skip to content

Commit

Permalink
Add numlock, capslock, and scrollock
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Mar 4, 2024
1 parent c2d4f15 commit 142e313
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions web/js/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,29 @@ const api = (() => {

const decodeBytes = (b) => String.fromCharCode.apply(null, new Uint8Array(b))

const keyboardPress = (pressed = false, e) => {
const keyboardPress = (() => {
// 0 1 2 3 4 5 6
// [CODE ] P MOD
const buffer = new ArrayBuffer(7);
const dv = new DataView(buffer);

// 0 1 2 3 4 5 6
dv.setUint8(4, pressed ? 1 : 0)
const k = libretro.map('', e.code);
dv.setUint32(0, k)

// meta keys
let mod = 0;

e.altKey && (mod |= libretro.mod.ALT)
e.ctrlKey && (mod |= libretro.mod.CTRL)
e.metaKey && (mod |= libretro.mod.META)
e.shiftKey && (mod |= libretro.mod.SHIFT)

dv.setUint16(5, mod)

webrtc.keyboard(buffer);
}
return (pressed = false, e) => {
const key = libretro.mod;
const code = libretro.map('', e.code);
const mod = 0
| (e.altKey && key.ALT)
| (e.ctrlKey && key.CTRL)
| (e.metaKey && key.META)
| (e.shiftKey && key.SHIFT)
| (e.getModifierState('NumLock') && key.NUMLOCK)
| (e.getModifierState('CapsLock') && key.CAPSLOCK)
| (e.getModifierState('ScrollLock') && key.SCROLLOCK)
dv.setUint32(0, code);
dv.setUint8(4, +pressed);
dv.setUint16(5, mod)
webrtc.keyboard(buffer);
}
})();

const mouseMove = (() => {
// 0 1 2 3 4
Expand Down Expand Up @@ -312,17 +314,13 @@ libretro = function () {// RETRO_KEYBOARD

const retroMod = {
NONE: 0x0000,

SHIFT: 0x01,
CTRL: 0x02,
ALT: 0x04,
META: 0x08,

// RETROKMOD_NUMLOCK = 0x10,
// RETROKMOD_CAPSLOCK = 0x20,
// RETROKMOD_SCROLLOCK = 0x40,

// RETROKMOD_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
NUMLOCK: 0x10,
CAPSLOCK: 0x20,
SCROLLOCK: 0x40,
};

const _map = (key = '', code = '') => {
Expand Down

0 comments on commit 142e313

Please sign in to comment.