Skip to content

Support for getting and setting the hotkey of a shortcut? #3

@fgimian

Description

@fgimian

Hey again, I noticed that you have the function definitios for getting and setting Hotkeys in the ShellLinkV class.

After a little reading and experimenting, I think I've got some rough code for obtaining the hotkey:

    public sealed class WindowsShortcut : IDisposable
    {
...
        private const uint HOTKEYF_ALT = 0x04;
        private const uint HOTKEYF_CONTROL = 0x02;
        private const uint HOTKEYF_EXT = 0x08;
        private const uint HOTKEYF_SHIFT = 0x01;
...
        public string? HotKey
        {
            get
            {
                unsafe
                {
                    ushort hotkeyCode = 0;
                    this.inst->Vtbl->GetHotKey(this.inst, &hotkeyCode);

                    ushort upper = (ushort)(hotkeyCode >> 8);
                    ushort lower = (ushort)(hotkeyCode & 0xff);

                    string shortcut = "";

                    if ((upper & HOTKEYF_CONTROL) != 0)
                    {
                        shortcut += "CTRL + ";
                    }

                    if ((upper & HOTKEYF_SHIFT) != 0)
                    {
                        shortcut += "SHIFT + ";
                    }

                    if ((upper & HOTKEYF_ALT) != 0)
                    {
                        shortcut += "ALT + ";
                    }

                    if ((upper & HOTKEYF_EXT) != 0)
                    {
                        shortcut += "EXT + ";
                    }


                    shortcut += (char)lower;
                    return shortcut;
                }
            }

Note that the lower byte is a bit tricky when it comes to keys such as HOME, END, PGUP & PGDOWN etc. My code above doesn't deal with that properly just yet.

Of course, I'm just creating a string representation of the hotkey above, but perhaps we should have a class with booleans for each of the modifier keys and some clean way to specify the virtual key code, including those special keys.

Happy to assist further if you would like to provide a little guidance on how you would like a hotkey represented.

Huge thanks
Fotis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions