Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

User Image
AJ☺llyMusicHead
12 discussion posts
Hello, hope all is well.

Could someone confirm this for me please? I've tested my keyboard with other scancode and VKey detection software and it isn't sending both WIN Keys in any of them.

Code

/*
    This is a minimal version of the function I am developing just to hightlight the behaviour of WIN Keys
    Whatever WIN key is pressed, IsKeyDown always returns true values for both WIN keys.

    To test this function, no hotkey assignment is needed
    Load script into DF script editor
    Hold down either WIN key and click <Run Code> button in DF script editor
*/
using System;
using System.Drawing;

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        /*
            For calling directly from a hotkey combo 
            The assigned function hotkey needs to have a relevant WIN or MODIFIER key assigned in DF to actually work
            i.e Function Hotkey = WIN + CTRL + W
            But as DF doesn't distinguish between LEFT or RIGHT in hotkey assignments we do it in code

            VK_SHIFT 16 (0x10)
            VK_CONTROL 17 (0x11)
            VK_MENU 18 (0x12)

            VK_LWIN 91 (0x5B)
            VK_LSHIFT 16 (0xA0)
            VK_LCONTROL 17 (0xA2)
            VK_LMENU 18 (0xA4)
            
            VK_RWIN 92 (0x5C)
            VK_RSHIFT 161 (0xA1)
            VK_RCONTROL 163 (0xA3)
            VK_RMENU 165 (0xA5)
            VK_APPS 93 (0x5D)
        */
        string sdbugtext = "";
        string sNewLine = Environment.NewLine + Environment.NewLine;

        // First check what WIN keys are pressed to run custom task assigned to WIN Key combo
        //if (BFS.Input.IsKeyDown("91") && BFS.Input.IsKeyDown("92"))
        if (BFS.Input.IsKeyDown("91;92"))
        {
            // BOTH WinKey Combo task
            // First check for both WIN Keys as when both are pressed either WIN key will return true
            sdbugtext = "!!! BOTH WIN KEYS PRESSED !!!" + sNewLine;
        }
        else if (BFS.Input.IsKeyDown("91"))
        {
            // LEFT WinKey Combo task
            sdbugtext = "!!! LEFT WIN KEY PRESSED !!!" + sNewLine;
        }
        else if (BFS.Input.IsKeyDown("92"))
        {
            // RIGHT WinKey Combo task
            sdbugtext = "!!! RIGHT WIN KEY PRESSED !!!" + sNewLine;
        }
        else
        {
            // Won't arrive here if function is called directly from a hotkey combo with a WIN key
            // No WIN keys are pressed so do nothing and return
            sdbugtext = "!!! NO WIN KEY PRESSED !!!" + sNewLine;
            //BFS.Dialog.ShowMessageInfo(sdbugtext);
            //return;
        }

        // Show Debug text 
        sdbugtext = sdbugtext + "WIN LEFT[" + BFS.Input.IsKeyDown("91") + "]     :     WIN RIGHT[" + BFS.Input.IsKeyDown("92") + "]" + sNewLine;
        /*
        // Debug text to show other modififer key checks
        // RIGHT ALT also shows LEFT CTRL[True] which is a Windows VKey feature anyway
        sdbugtext = sdbugtext + "LEFT SHIFT[" + BFS.Input.IsKeyDown("160") + "]     :     RIGHT SHIFT[" + BFS.Input.IsKeyDown("161") + "]" + sNewLine;
        sdbugtext = sdbugtext + "LEFT CTRL[" + BFS.Input.IsKeyDown("162") + "]     :     RIGHT CTRL[" + BFS.Input.IsKeyDown("163") + "]" + sNewLine;
        sdbugtext = sdbugtext + "LEFT ALT[" + BFS.Input.IsKeyDown("164") + "]     :     RIGHT ALT[" + BFS.Input.IsKeyDown("165") + "]" + sNewLine;
        sdbugtext = sdbugtext + "                                      APPS Key[" + BFS.Input.IsKeyDown("93") + "]" + sNewLine;
        */
        BFS.Dialog.ShowMessageInfo(sdbugtext);
    }
}


Thanks and all the best :)
Sep 26, 2018 (modified Sep 26, 2018)  • #1
Jon Tackabury (BFS)'s profile on WallpaperFusion.com
Unfortunately the system doesn't differentiate between the left and right Windows keys for this function, it's an all-or-nothing thing.
Oct 1, 2018  • #2
User Image
AJ☺llyMusicHead
12 discussion posts
Ah, good to know, thanks for letting me know, thought I was going nuts haha :D

I did find a workaround :)

Code

public static void Run(IntPtr windowHandle)
    {
        string sdbugtext = "";
        
        /*
            Call the function IsKeyPressed to detect left and right Windows keys states
            VK_LWIN 91 (0x5B)
            VK_RWIN 92 (0x5C)
        */

        // Can use hexadecimal or integer values
        bool bvklwin = IsKeyPressed(91);
        bool bvkrwin = IsKeyPressed(0x5C);

        // Check for both WIN Keys first
        if (bvklwin @ bvlrwin) {
            sdbugtext = sdbugtext + "BOTH WINKEYS PRESSED" + Environment.NewLine;
        else if (bvklwin) {
            sdbugtext = sdbugtext + "LEFT WINKEY PRESSED" + Environment.NewLine;
        } else if (bvkrwin) {
            sdbugtext = sdbugtext + "RIGHT WINKEY PRESSED" + Environment.NewLine;
        } else {
            sdbugtext = sdbugtext + "NO WIN KEY PRESSED" + Environment.NewLine;
        }
        
        BFS.Dialog.ShowMessageInfo(sdbugtext);
    }

    // Load user32 function GetAsyncKeyState
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern ushort GetAsyncKeyState(int piVKey);

    // Alternative IsKeyDown function to distinguish Left and Right Win Keys
    // But can be used for any valid VKey integer code
    public static bool IsKeyPressed(int piVKey) {
        return 0 != (GetAsyncKeyState(piVKey) & 0x8000);
    }
Oct 12, 2018  • #3
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Oh nice, thanks! We'll see if we might be able to incorporate that workaround into the IsKeyDown function as well, thanks for posting that!
Oct 17, 2018  • #4
Keith Lammers (BFS)'s profile on WallpaperFusion.com
We've just released a new VoiceBot Beta version, and this issue should be all fixed up. Please let us know if you run into any trouble after updating.

Thanks!
May 16, 2019  • #5
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)