Beispiel #1
0
        public static Process ActiveWindowProcess()
        {
            uint pid = 0;

            WinAPI.GetWindowThreadProcessId(Locales.ActiveWindow(), out pid);
            var prc = Process.GetProcessById((int)pid);

            return(prc);
        }
Beispiel #2
0
        public static Process ActiveWindowProcess()
        {
            uint pid = 0;

            WinAPI.GetWindowThreadProcessId(Locales.ActiveWindow(), out pid);
            Process prc = null;

            try { prc = Process.GetProcessById((int)pid); } catch { Logging.Log("Process with id [" + pid + "] not exist...", 1); }
            return(prc);
        }
Beispiel #3
0
 public static void Init()
 {
     if (running)
     {
         bool exist = true;
         if (Environment.Is64BitOperatingSystem)
         {
             if (Process.GetProcessesByName("jkl").Length > 0)
             {
                 Logging.Log("[JKL] > JKL already running.");
             }
             else
             {
                 exist = false;
             }
         }
         else
         {
             if (Process.GetProcessesByName("jklx86").Length > 0)
             {
                 Logging.Log("[JKL] > JKLx86 already running.");
             }
             else
             {
                 exist = false;
             }
         }
         if (!exist)
         {
             Logging.Log("[JKL] > JKL seems closed, restarting...");
             running = false;
         }
     }
     if (HWND == IntPtr.Zero)
     {
         Logging.Log("[JKL] > Initializing JKL HWND server...");
         WNDPROC_DELEGATE = jklWndProc;
         var wnd_class = new WinAPI.WNDCLASS();
         wnd_class.lpszClassName = "_XHIDDEN_HWND_SERVER";
         wnd_class.lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(WNDPROC_DELEGATE);
         UInt16 cls_reg    = WinAPI.RegisterClassW(ref wnd_class);
         int    last_error = Marshal.GetLastWin32Error();
         if (cls_reg == 0 && last_error != 0)
         {
             Logging.Log("[JKL] > Could not register window class, for jkl Hidden Server, err: " + last_error, 1);
         }
         HWND = WinAPI.CreateWindowExW(0, "_XHIDDEN_HWND_SERVER", "_XHIDDEN_HWND_SERVER", 0, 0, 0, 0, 0,
                                       IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
     }
     if (!running)
     {
         if (jklExist())
         {
             if (Environment.Is64BitOperatingSystem)
             {
                 Logging.Log("[JKL] > Starting jkl.exe...");
                 var jkl = new ProcessStartInfo();
                 jkl.UseShellExecute  = true;
                 jkl.FileName         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jkl.exe");
                 jkl.WorkingDirectory = Path.Combine(Path.GetTempPath());
                 Process.Start(jkl);
             }
             else
             {
                 Logging.Log("[JKL] > Starting \"jklx86.exe -msg\"...");
                 var jkl = new ProcessStartInfo();
                 jkl.UseShellExecute  = true;
                 jkl.FileName         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jklx86.exe");
                 jkl.Arguments        = "-msg";
                 jkl.WorkingDirectory = Path.Combine(Path.GetTempPath());
                 Process.Start(jkl);
             }
             var umsgID = Path.Combine(Path.GetTempPath(), "umsg.id");
             var tries  = 0;
             while (!File.Exists(umsgID))
             {
                 Thread.Sleep(350);
                 tries++;
                 if (tries > 20)
                 {
                     Logging.Log("[JKL] > Error, umsg.id not found after 20 tries by 350 ms timeout.", 1);
                     Destroy();
                     break;
                 }
             }
             if (tries <= 20)
             {
                 Logging.Log("[JKL] > umsg.id found, after " + tries + " tries * 350ms timeout.");
                 Logging.Log("[JKL] > Retrieving umsg.id...");
                 jkluMSG = Convert.ToInt32(File.ReadAllText(umsgID));
                 File.Delete(umsgID);
                 KMHook.DoLater(() => CycleAllLayouts(Locales.ActiveWindow()), 350);
                 running = true;
             }
         }
         else
         {
             Logging.Log("[JKL] > " + jklInfoStr, 1);
         }
         Logging.Log("[JKL] > Init done, umsg: [" + jkluMSG + "], JKLXServ: [" + HWND + "].");
     }
 }