Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hexidecmial codes are incorrect. #364

Closed
testfax opened this issue Aug 22, 2023 · 5 comments
Closed

hexidecmial codes are incorrect. #364

testfax opened this issue Aug 22, 2023 · 5 comments

Comments

@testfax
Copy link

testfax commented Aug 22, 2023

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
Copy link
Owner

univrsal commented Aug 23, 2023

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

@testfax
Copy link
Author

testfax commented Aug 23, 2023

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
Copy link
Owner

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
Copy link
Author

testfax commented Aug 23, 2023

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
Copy link
Owner

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.

@univrsal univrsal closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants