question

JeongeunLee-9751 avatar image
0 Votes"
JeongeunLee-9751 asked JeongeunLee-9751 commented

shortcut(with virtual key) is not work on window 10 enterprise 2016

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!

dotnet-csharp
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

First time I've seen this, it doesn't work in window10 enterprise 2016..

0 Votes 0 ·

Hi @JeongeunLee-9751,
I saw that Castorix31 provided a detailed solution in another thread, did it solve your problem?
Best Regards,
Daniel Zhang

0 Votes 0 ·

I saw it and it doesn't work

0 Votes 0 ·

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered Castorix31 edited

Maybe you can test the sample I posted in this thread for [Ctrl + Win + Shift] + B
(only tested on Windows 10 Education)



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.