Files icon indicating copy to clipboard operation
Files copied to clipboard

Bug: Problem with mapping certain keys in action section

Open XTorLukas opened this issue 1 year ago • 12 comments
trafficstars

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 avatar May 15 '24 12:05 XTorLukas

Fyi @0x5bfa

yaira2 avatar May 15 '24 14:05 yaira2

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

yaira2 avatar May 15 '24 14:05 yaira2

@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

XTorLukas avatar May 15 '24 14:05 XTorLukas

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:)

0x5bfa avatar May 15 '24 18:05 0x5bfa

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

I use the Czech keyboard layout image

XTorLukas avatar May 15 '24 18:05 XTorLukas

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

XTorLukas avatar May 15 '24 18:05 XTorLukas

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

0x5bfa avatar May 15 '24 18:05 0x5bfa

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);

XTorLukas avatar May 15 '24 19:05 XTorLukas

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

I'll work on.

0x5bfa avatar May 15 '24 19:05 0x5bfa

Thanks!

yaira2 avatar May 15 '24 20:05 yaira2

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 avatar May 15 '24 23:05 0x5bfa

@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.

XTorLukas avatar May 16 '24 19:05 XTorLukas

@XTorLukas thank you for your detailed report and fix!

yaira2 avatar May 24 '24 13:05 yaira2