Exemplo n.º 1
0
        private static int GetExeID()
        {
            IntPtr hwnd = WindowsAPI.GetForegroundWindow();
            uint   pid;

            WindowsAPI.GetWindowThreadProcessId(hwnd, out pid);

            int processId = (int)pid;

            IntPtr hprocess = WindowsAPI.OpenProcess(ProcessAccessFlags.All,
                                                     false, processId);
            var buffer = new StringBuilder(1024);
            int size   = buffer.Capacity;

            if (WindowsAPI.QueryFullProcessImageName(hprocess, 0, buffer, out size))
            {
                buffer.ToString();
            }

            Process p = Process.GetProcessById((int)pid);

            DBUtils.OpenConection();
            if (p != null)
            {
                try
                {
                    exeID = DBUtils.GetExeID(p);
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
            }
            isTrackable = Convert.ToBoolean(DBUtils.ExecuteScalar(string.Format("SELECT filter FROM Programs WHERE Id = {0} ", exeID)));
            DBUtils.CloseConnection();
            return(1);
        }
        /* Converts keyboard scan code to symbol */
        public static string GetCharsFromKeys(Keys keys)
        {
            IntPtr inputLocaleIdentifier = WindowsAPI.GetKeyboardLayout(WindowsAPI.GetWindowThreadProcessId(WindowsAPI.GetForegroundWindow(), IntPtr.Zero));
            bool   shift         = Control.ModifierKeys.HasFlag(Keys.Shift);
            bool   caps          = Control.IsKeyLocked(Keys.Capital);
            var    buf           = new StringBuilder(256);
            var    keyboardState = new byte[256];

            if (shift)
            {
                keyboardState[(int)Keys.ShiftKey] = 0xff;
            }

            //WindowsAPI.ToUnicode((uint)keys, 0, keyboardState, buf, 256, 0);
            WindowsAPI.ToUnicodeEx((uint)keys, 0, keyboardState, buf, 256, 0, inputLocaleIdentifier);
            if (caps && !shift || !caps && shift)
            {
                return(buf.ToString().ToUpper());
            }
            else
            {
                return(buf.ToString().ToLower());
            }
        }