univrsal / input-overlay

Show keyboard, gamepad and mouse input on stream
GNU General Public License v2.0
2.63k stars 235 forks source link

hexidecmial codes are incorrect. #364

Closed testfax closed 10 months ago

testfax commented 10 months ago

Describe the bug It appears that the hexidecmial codes are incorrect for the ASCII standard 8bit integer system.

To Reproduce Click on any element to edit. Ensure record key is selected. Type a letter, for example "d".

Expected behavior The expected behavior should be for it to record the correct ASCII hex code for the letter "d" as "0x64", however it inputs "0x20".

Screenshots http://puu.sh/JOkJ9/94596b1320.png

Additional information: vc.js

function key_to_vc(e) {
    const key = e.key
    const keyCode = key.charCodeAt(0);
    const hexCode = keyCode.toString(16)

    return hexCode

    // let key = e.code;

    // if (key.indexOf("Numpad") >= 0 && /^[0-9]$/g.test(key.slice(-1))) {
    //     // Numpad has special handling
    //     // all keys Numpad1 through Numpad9 should use the key
    //     // so that we can tell numpad buttons with numlock on apart from
    //     // numpad buttons with numpad off
    //     key = key.slice(0, -1) + e.key;
    // }

    // if (key === "NumpadDecimal" && e.keyCode === 46)
    //     key = "NumpadDelete";

    // if (key2vc.has(key))
    //     return key2vc.get(key);
    // return 0;
}

elements.js line 228 add vc = parseInt(vc,16)

will display the correct hexcodes for all modifiers and keys pressed including numpad. this will fix the JSON file and it will ensure your preview is correct. This also fixes all modifier issues and keypad issues.

However, the actual plugin part for OBS will need modification. That's beyond me.

Additional context https://en.wikipedia.org/wiki/ASCII https://bytetool.web.app/en/ascii/

univrsal commented 10 months ago

The key codes have nothing to do with ASCII. Each key has an assigned code, which is defined by libuiohook.

testfax commented 10 months ago

bewildering....

How do you add key modifiers then? Its all predefined and that's not good if you have key combinations with shift+d or shift+F1. You are stuck with predefined, not good at all.

univrsal commented 10 months ago

bewildering....

How would you represent keys like F1 as an ASCII character? The function you suggested would take the first character of the key name, so F1 through F12 would in this case turn into the ASCII code for 'F' and all use the same key code, which is obviously wrong. Since you'll need exceptions for all keys that can't be converted to ASCII you might as well just not use that system at all. Regardless, I didn't come up with the key codes, I'm just using a library which allows cross-platform global input hooking.

How do you add key modifiers then?

As of right now, you don't.

Its all predefined and that's not good if you have key combinations with shift+d or shift+F1. You are stuck with predefined, not good at all.

It doesn't have anything to do with the codes being "predefined", modifiers like shift or control are passed separately for each key event and as of right now they just aren't handled. See #73

testfax commented 10 months ago

convert it to binary and let it be represented by its F and 1 binary number. I'm not sure how things go in Cmake or what ever was used there, but if there's a way to turn "46 31" into "F1" there. JSON code: "46 31" instead of a predefined vc(F1,xxxx). Just an idea. If you need to include a modifier, same thing "ShiftRight" into binary and send on its way. I would probably either make the code value an array or new object for "modifier": "binary"

document.addEventListener("keydown", function(event) {
    if (event.key === "F1") {
        // F1 key was pressed
        console.log("F1 key pressed");
        // convert to binary and push into the code object in its elements array.
    }
});
univrsal commented 10 months ago

I don't think you understand what I'm saying. The input events are handled by this library. It sends inputs with these predefined key codes. There's no reason to use other key codes because they'd ultimately have to be converted back to the ones that libuiohook uses.