Hello,
I'm programming an application where ctrl + shift + win + b is pressed as virtual key.
It's work in window 10 Home and Pro. but is not work on Enterprise 2016.
This shortcut works when you press it directly with keyboard.
and It works when you press ctrl+shift+win as a virtual key and press B directly on the keyboard.
BUT press ctrl+shift+win+B press as a virtual key? It's not works.
Please help me. I have nothing to point out about this phenomenon.
I wrote this program in C# and this is my code.
[StructLayout(LayoutKind.Sequential)]
internal struct KEYBDINPUT
{
public ushort Vk;
public ushort Scan;
public uint Flags;
public uint Time;
public IntPtr ExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
internal struct INPUT
{
public uint Type;
public MOUSEKEYBDHARDWAREINPUT Data;
}
static class Program
{
[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(uint bVk, uint bScan, uint dwFlags, uint dwExtraInfo);
[DllImport("user32.dll", SetLastError = true)]
private static extern uint SendInput(uint numberOfInputs, INPUT[] inputs, int sizeOfInputStructure);
[DllImport("user32.dll", SetLastError = true)]
private static extern uint MapVirtualKey(int wCode, int wMapType);
public static void SendKeyDown(KeyCode keyCode)
{
INPUT input = new INPUT
{
Type = 1
};
input.Data.Keyboard = new KEYBDINPUT();
input.Data.Keyboard.Vk = (ushort)keyCode;
input.Data.Keyboard.Scan = 0;
input.Data.Keyboard.Flags = 0;
input.Data.Keyboard.Time = 0;
input.Data.Keyboard.ExtraInfo = IntPtr.Zero;
INPUT[] inputs = new INPUT[] { input };
if (SendInput(1, inputs, Marshal.SizeOf(typeof(INPUT))) == 0)
{
throw new Exception();
}
}
public static void SendKeyDownScan(KeyCode keyCode)
{
INPUT input = new INPUT
{
Type = 1
};
input.Data.Keyboard = new KEYBDINPUT();
input.Data.Keyboard.Vk = 0;
input.Data.Keyboard.Scan = (ushort)keyCode;
input.Data.Keyboard.Flags = 0|8;
input.Data.Keyboard.Time = 0;
input.Data.Keyboard.ExtraInfo = IntPtr.Zero;
INPUT[] inputs = new INPUT[] { input };
if (SendInput(1, inputs, Marshal.SizeOf(typeof(INPUT))) == 0)
{
throw new Exception();
}
}
public static void SendKeyUp(KeyCode keyCode)
{
INPUT input = new INPUT
{
Type = 1
};
input.Data.Keyboard = new KEYBDINPUT();
input.Data.Keyboard.Vk = (ushort)keyCode;
input.Data.Keyboard.Scan = 0;
input.Data.Keyboard.Flags = 2;
input.Data.Keyboard.Time = 0;
input.Data.Keyboard.ExtraInfo = IntPtr.Zero;
INPUT[] inputs = new INPUT[] { input };
if (SendInput(1, inputs, Marshal.SizeOf(typeof(INPUT))) == 0)
throw new Exception();
}
public static void SendKeyUpScan(KeyCode keyCode)
{
INPUT input = new INPUT
{
Type = 1
};
input.Data.Keyboard = new KEYBDINPUT();
input.Data.Keyboard.Vk = 0;
input.Data.Keyboard.Scan = (ushort)keyCode;
input.Data.Keyboard.Flags = 2|8;
input.Data.Keyboard.Time = 0;
input.Data.Keyboard.ExtraInfo = IntPtr.Zero;
INPUT[] inputs = new INPUT[] { input };
if (SendInput(1, inputs, Marshal.SizeOf(typeof(INPUT))) == 0)
throw new Exception();
}
public enum KeyCode : ushort
{
KEY_B_D = 0x30,
KEY_B_U = 0x30,
CONTROL = 0x11,
LSHIFT = 160,
LWIN = 0x5b,
}
public static void ScreenReset(object sender, System.EventArgs e)
{
try
{
SendKeyDown(KeyCode.LSHIFT);
SendKeyDown(KeyCode.CONTROL);
SendKeyDown(KeyCode.LWIN);
SendKeyDownScan(KeyCode.KEY_B_D);
SendKeyUpScan(KeyCode.KEY_B_U);
SendKeyUp(KeyCode.LSHIFT);
SendKeyUp(KeyCode.CONTROL);
SendKeyUp(KeyCode.LWIN);
}
}
}
these are part of the code!