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

Bug: Problem with mapping certain keys in action section #15403

Closed
XTorLukas opened this issue May 15, 2024 · 13 comments
Closed

Bug: Problem with mapping certain keys in action section #15403

XTorLukas opened this issue May 15, 2024 · 13 comments
Labels
area - actions Features or bug reports relating to actions

Comments

@XTorLukas
Copy link
Contributor

XTorLukas commented May 15, 2024

Description

I discovered a small bug where two characters are not displayed correctly:

image

  • KEY: ; wrong map to ´;
    image

  • KEY: ) wrong map to ¨)
    image

but this problem is only in the text string representation, the KEY function is recorded correctly

Steps To Reproduce

  1. Fix string representations mapping this keys

Files Version

3.4.1.0

Windows Version

10.0.22631.3593

Log File

There are no errors

@XTorLukas XTorLukas added the bug label May 15, 2024
@yaira2
Copy link
Member

yaira2 commented May 15, 2024

Fyi @0x5bfa

@yaira2 yaira2 changed the title Issue: Problem with mapping keys in action section Bug: Problem with mapping keys in action section May 15, 2024
@yaira2 yaira2 changed the title Bug: Problem with mapping keys in action section Bug: Problem with mapping certain keys in action section May 15, 2024
@yaira2
Copy link
Member

yaira2 commented May 15, 2024

@XTorLukas thank you for the feedback. Aside from this issue, do you have any other thoughts or feedback on this feature?

@XTorLukas
Copy link
Contributor Author

@yaira2 Maybe I would like to be able to map also numeric keys e.g. Num0, Num1 and others and divide e.g. + and NumPlus
image

@0x5bfa 0x5bfa self-assigned this May 15, 2024
@0x5bfa
Copy link
Member

0x5bfa commented May 15, 2024

Thanks for the feedback!

It looks like your keyboard is not US keyboard, what keyboard type are you using?
And, when you have a time to do, could you do that same in Windows Terminal > Settings > Actions? If it works well, it’s our problem, let me know:)

@XTorLukas
Copy link
Contributor Author

It looks like your keyboard is not US keyboard, what keyboard type are you using?

I use the Czech keyboard layout
image

@XTorLukas
Copy link
Contributor Author

And, when you have a time to do, could you do that same in Windows Terminal > Settings > Actions?

In other applications it works correctly

PowerToys

Terminal

image
image

@0x5bfa
Copy link
Member

0x5bfa commented May 15, 2024

Thanks! It looks like Files has an issue around humanizing input keys.

@XTorLukas
Copy link
Contributor Author

Maybe it will be useful.

I don't know how the implementation is used here, but I personally use this class:

public class KeyCodeConverter
{
    [DllImport("user32.dll")]
    private static extern int ToUnicode(
        uint wVirtKey,
        uint wScanCode,
        byte[] lpKeyState,
        [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwszBuff,
        int cchBuff,
        uint wFlags);

    [DllImport("user32.dll")]
    private static extern bool GetKeyboardState(byte[] lpKeyState);

    [DllImport("user32.dll")]
    private static extern uint MapVirtualKey(uint uCode, uint uMapType);

    [DllImport("user32.dll")]
    private static extern IntPtr GetKeyboardLayout(uint idThread);

    public static char ConvertKeyCodeToChar(Keys key)
    {
        char ch = '\0';
        byte[] keyboardState = new byte[256];
        if (!GetKeyboardState(keyboardState))
        {
            return ch;
        }

        uint virtualKey = (uint)key;
        uint scanCode = MapVirtualKey(virtualKey, 0);
        StringBuilder stringBuilder = new StringBuilder(2);

        int result = ToUnicode(virtualKey, scanCode, keyboardState, stringBuilder, stringBuilder.Capacity, 0);
        if (result > 0)
        {
            ch = stringBuilder[0];
        }

        return ch;
    }

Use in code

char character = KeyCodeConverter.ConvertKeyCodeToChar(keyData);

@0x5bfa
Copy link
Member

0x5bfa commented May 15, 2024

@yaira2 ToUnicode seems to be actually needed though I did remove. cinqmilleans's implementation is always correct...

I'll work on.

@yaira2
Copy link
Member

yaira2 commented May 15, 2024

Thanks!

@0x5bfa
Copy link
Member

0x5bfa commented May 15, 2024

It looks like we didn't remove that ToUnicode line.
I don't have a way to test.

@XTorLukas If you have a solution to this, do you wanna open a PR for this?

@0x5bfa 0x5bfa removed their assignment May 15, 2024
@XTorLukas
Copy link
Contributor Author

@0x5bfa I have my general solution, but I'm here for a short time and need time to get my head around the code, it's not easy with complex code.

But I'm certainly willing to help if I know the solution, just the correct implementation is important.

@yaira2
Copy link
Member

yaira2 commented May 24, 2024

@XTorLukas thank you for your detailed report and fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area - actions Features or bug reports relating to actions
Projects
Archived in project
Development

No branches or pull requests

3 participants