LAB02-Research / HASS.Agent

Windows-based client for Home Assistant. Provides notifications, quick actions, commands, sensors and more.
https://hassagent.lab02-research.org
MIT License
1.48k stars 65 forks source link

Win+Shift+Left #418

Open urtaevS opened 3 days ago

urtaevS commented 3 days ago

How I can send MultipleKeysCommand Win+Shift+Left?

BitWuehler commented 3 days ago

I had the same Problem. The problem is the sendkeys funktion from Windows, that doesn't supports holding the WIN-key. I found a solution in this powershell-script. You just can add this as a powershell ps1 file in hass.agent and it works.

Add-Type @"
using System;
using System.Runtime.InteropServices;

public class Keyboard {
    [DllImport("user32.dll", SetLastError = true)]
    public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

    public const int KEYEVENTF_EXTENDEDKEY = 0x0001;
    public const int KEYEVENTF_KEYUP = 0x0002;
    public const byte VK_SHIFT = 0x10;
    public const byte VK_LEFT = 0x25;
    public const byte VK_LWIN = 0x5B;

    public static void KeyDown(byte keyCode) {
        keybd_event(keyCode, 0, KEYEVENTF_EXTENDEDKEY, UIntPtr.Zero);
    }

    public static void KeyUp(byte keyCode) {
        keybd_event(keyCode, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, UIntPtr.Zero);
    }
}
"@

[Keyboard]::KeyDown([Keyboard]::VK_LWIN)
[Keyboard]::KeyDown([Keyboard]::VK_SHIFT)
[Keyboard]::KeyDown([Keyboard]::VK_LEFT)
[Keyboard]::KeyUp([Keyboard]::VK_LEFT)
[Keyboard]::KeyUp([Keyboard]::VK_SHIFT)
[Keyboard]::KeyUp([Keyboard]::VK_LWIN)