예제 #1
0
 public static void SetPhysicalKeyStatus(int KeyValue, Status s)
 {
     if (UtilWinApi.GetKeyState(KeyValue) != (int)s)
     {
         PressByKeyValue(KeyValue);
     }
 }
예제 #2
0
        //PressKey(Keys.A, false);
        //PressKey(Keys.A, true);
        private static void PressByKeys(Keys key, bool up)
        {
            const int KEYEVENTF_EXTENDEDKEY = 0x1;
            const int KEYEVENTF_KEYUP       = 0x2;

            if (up)
            {
                //UtilWinApi.keybd_event((byte)key, bScan, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
                UtilWinApi.keybd_event((byte)key, (byte)(key), KEYEVENTF_KEYUP, (UIntPtr)0);
            }
            else
            {
                UtilWinApi.keybd_event((byte)key, 0x45, 0, (UIntPtr)0);
            }
        }
예제 #3
0
        private static void PressByKeyValue(int KeyValue, bool up)
        {
            //var a = Convert.ToInt32("1E", 16);
            const int KEYEVENTF_EXTENDEDKEY = 0x1;
            const int KEYEVENTF_KEYUP       = 0x2;

            if (up)
            {
                //UtilWinApi.keybd_event((byte)key, 30, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
                UtilWinApi.keybd_event((byte)KeyValue, 0, KEYEVENTF_KEYUP, (UIntPtr)0);
            }
            else
            {
                UtilWinApi.keybd_event((byte)KeyValue, 0, 0, (UIntPtr)0);
            }
        }
예제 #4
0
 public static void SingletonUi()
 {
     try
     {
         using (var currentP = Process.GetCurrentProcess())
         {
             foreach (var p in Process.GetProcessesByName(currentP.ProcessName))
             {
                 if (p.Id == currentP.Id)
                 {
                     continue;
                 }
                 UtilWinApi.SetForegroundWindow(p.MainWindowHandle);
                 UtilWinApi.ShowWindowAsync(p.MainWindowHandle, UtilWinApi.SwRestore);
                 currentP.Kill();
             }
         }
     }
     catch (Exception ex)
     {
         Logger.LogThrowMessage(string.Format("Failed to leave unique UI."), new StackFrame(0).GetMethod().Name, ex.Message);
     }
 }