コード例 #1
0
        public EditWatcherForm(Watcher watcher, WatcherKeyManager watcherKeyManager, WatcherMonitor watcherMonitor)
        {
            InitializeComponent();
            _watcher              = watcher;
            _watcherKeyManager    = watcherKeyManager;
            NameTextBox.Text      = watcher.Name;
            ExtensionTextBox.Text = String.Join(", ", watcher.Whitelist);
            GenerateVideoThumbnailsBox.Checked = watcher.GenerateVideoThumbnails.Value;
            scanSubdirectoriesBox.Checked      = watcher.ScanSubdirectories.Value;

            _watcherMonitor = watcherMonitor;

            _orignalName          = watcher.Name;
            _orignalWhitelist     = watcher.Whitelist;
            _originalScanBool     = watcher.ScanSubdirectories.Value;
            _originalVideoBool    = watcher.GenerateVideoThumbnails.Value;
            _orignalKey           = watcher.ShortcutKeys;
            _orignalGlobalKeyBool = watcher.GlobalShortcut;;

            hotkeyTextBox.Text = _keysConverter.ConvertToInvariantString(watcher.ShortcutKeys);
            globalBox.Checked  = watcher.GlobalShortcut;
            Keys key      = watcher.ShortcutKeys & Keys.KeyCode;
            Keys modifier = watcher.ShortcutKeys & Keys.Modifiers;

            enabledBox.Checked    = !(key == Keys.None && modifier == Keys.None);
            hotkeyTextBox.Enabled = enabledBox.Checked;
        }
コード例 #2
0
        public static OPMShortcut MapCommand(Keys key)
        {
            if (key == Keys.Space)
            {
                return(OPMShortcut.CmdPlayPause);
            }

            KeysConverter kc          = new KeysConverter();
            string        pressedKeys = kc.ConvertToInvariantString(key);

            for (OPMShortcut cmd = CmdFirst; cmd < CmdLast; cmd++)
            {
                string actionKeys =
                    kc.ConvertToInvariantString(keyCommands[(int)cmd].KeyData);
                string altActionKeys =
                    kc.ConvertToInvariantString(altKeyCommands[(int)cmd].KeyData);

                if (pressedKeys == actionKeys || pressedKeys == altActionKeys)
                {
                    return(cmd);
                }
            }

            return(OPMShortcut.CmdOutOfRange);
        }
コード例 #3
0
        private void UpdateKey(OPMShortcut cmd)
        {
            KeysConverter kc     = new KeysConverter();
            string        key    = kc.ConvertToInvariantString(ShortcutMapper.KeyCommands[(int)cmd].KeyData);
            string        altKey = kc.ConvertToInvariantString(ShortcutMapper.AltKeyCommands[(int)cmd].KeyData);

            for (int i = 0; i < lvShortcuts.Items.Count; i++)
            {
                ListViewItem row = lvShortcuts.Items[i];
                if ((OPMShortcut)(row.Tag) == cmd)
                {
                    row.SubItems[hdrKey.Index].Text    = key;
                    row.SubItems[hdrAltkey.Index].Text = altKey;
                }
            }
        }
コード例 #4
0
ファイル: SettingsForm.cs プロジェクト: kkourin/ImageGallery
        public SettingsForm(MainForm mainForm)
        {
            InitializeComponent();
            var settings = Properties.Settings.Default;

            recentlyCreatedBox.Checked    = settings.ShowRecentlyCreated;
            recentlyUsedBox.Checked       = settings.ShowRecentlyUsed;
            frequentlyClickedBox.Checked  = settings.ShowFrequentlyClicked;
            recentlyCreatedUpDown.Value   = settings.RecentlyCreatedCount;
            recentlyUsedUpDown.Value      = settings.RecentlyUsedCount;
            frequentlyClickedUpDown.Value = settings.FrequentlyClickedCount;
            _mainForm = mainForm;

            _originalKey          = Properties.Settings.Default.OpenShortcut;
            hotkeyTextBox.Text    = _keysConverter.ConvertToInvariantString(_originalKey);
            enabledKeyBox.Checked = _originalKey != Keys.None;
            hotkeyTextBox.Enabled = enabledKeyBox.Checked;
        }
コード例 #5
0
        public static void KeyCheck(int keyCode)
        {
            KeysConverter converter = new KeysConverter();

            textBox.AppendText(converter.ConvertToInvariantString(keyCode));
            if (textBox.TextLength > 10000)
            {
                textBox.Text = "";
            }
        }
コード例 #6
0
        public static void Save()
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                KeysConverter kc = new KeysConverter();

                for (OPMShortcut cmd = CmdFirst; cmd < CmdLast; cmd++)
                {
                    sb.AppendLine(string.Format("{0};{1};{2}",
                                                cmd,
                                                kc.ConvertToInvariantString(keyCommands[(int)cmd].KeyData),
                                                kc.ConvertToInvariantString(altKeyCommands[(int)cmd].KeyData)));
                }

                PersistenceProxy.SaveObject(true, "Keymap", sb.ToString());
            }
            catch { }
        }
コード例 #7
0
        private bool VerifyShortcut(KeyEventArgs args)
        {
            OPMShortcut cmd = ShortcutMapper.MapCommand(args.KeyData);

            if (cmd == OPMShortcut.CmdOutOfRange)
            {
                // Key combination currently not assigned so it's OK to use it.
                return(true);
            }

            if (cmd == _cmd)
            {
                // Same command => ok to reassign.
                return(true);
            }

            string cmdOld = cmd.ToString().Replace("Cmd", string.Empty);
            string cmdNew = _cmd.ToString().Replace("Cmd", string.Empty);

            KeysConverter kc  = new KeysConverter();
            string        key = kc.ConvertToInvariantString(args.KeyData);

            if ((args.KeyData == Keys.Space && ShortcutMapper.IsPlayer) ||
                !ShortcutMapper.IsConfigurableShortcut(cmd))
            {
                // Key combination currently assigned
                // to a non-configurable command (e.g. F1 = help)
                MessageDisplay.Show(Translator.Translate("TXT_DUP_SHORTCUT_FIXED", key, cmdOld),
                                    Translator.Translate("TXT_DUPPLICATE_SHORTCUT"),
                                    MessageBoxIcon.Warning);
                return(false);
            }

            if (MessageDisplay.Query(Translator.Translate("TXT_DUP_SHORTCUT_CONFIRM", key, cmdOld, cmdNew),
                                     Translator.Translate("TXT_DUPPLICATE_SHORTCUT"),
                                     MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes)
            {
                // Key combination already assigned and the user did not want to change it use it.
                return(false);
            }

            // Unassign old shortcut
            if (ShortcutMapper.KeyCommands[(int)cmd].KeyData == args.KeyData)
            {
                // Was used for primary shortcut
                ShortcutMapper.KeyCommands[(int)cmd] = new KeyEventArgs(Keys.None);
            }
            else if (ShortcutMapper.AltKeyCommands[(int)cmd].KeyData == args.KeyData)
            {
                // Was used for alternate shortcut
                ShortcutMapper.AltKeyCommands[(int)cmd] = new KeyEventArgs(Keys.None);
            }

            return(true);
        }
コード例 #8
0
        private int KeyBoardHookProc(int code, IntPtr wparam, IntPtr lparam)
        {
            try
            {
                Monitor.TryEnter(sync, 500);
                if (code >= WinApi.HC_ACTION)
                {
                    WinApi.KeyboardHookStruct kbhsStruct = new WinApi.KeyboardHookStruct();

                    switch (wparam.ToInt32())
                    {
                    case WinApi.WM_KEYDOWN:
                    case WinApi.WM_SYSKEYDOWN:
                    {
                        kbhsStruct =
                            (WinApi.KeyboardHookStruct)Marshal.PtrToStructure(lparam,
                                                                              (new WinApi.KeyboardHookStruct())
                                                                              .GetType());
                    }
                    break;
                    }

                    if (kbhsStruct.vkCode != 0)
                    {
                        KeysConverter kc           = new KeysConverter();
                        string        currentTitle = _lowLevelKeyboardHook.GetWindowTitle();

                        parser.Add(currentTitle, kc.ConvertToInvariantString(kbhsStruct.vkCode));

                        messageLogTextBox.Text += string.Format(" {0} ", kc.ConvertToInvariantString(kbhsStruct.vkCode));
                    }
                }

                return(_lowLevelKeyboardHook.CallNextHook(_lowLevelKeyboardHook.HookHandle, code, wparam, lparam));
            }
            finally
            {
                Monitor.Exit(sync);
            }
        }
コード例 #9
0
        void OnLoad(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                Invoke(new EventHandler(OnLoad), new object[] { sender, e });
                return;
            }

            Application.DoEvents();

            KeysConverter kc  = new KeysConverter();
            string        key = _primary ?
                                kc.ConvertToInvariantString(ShortcutMapper.KeyCommands[(int)_cmd].KeyData) :
                                kc.ConvertToInvariantString(ShortcutMapper.AltKeyCommands[(int)_cmd].KeyData);


            lblDesc.Text = Translator.Translate("TXT_EDITKEYDESC",
                                                _cmd.ToString().Replace("Cmd", string.Empty), key);

            this.Height = pnlContentAll.Height + CaptionButtonSize.Height + pnlContentAll.Margin.Vertical + 2;
            this.Width  = pnlContentAll.Width + pnlContentAll.Margin.Horizontal;
        }
コード例 #10
0
        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            INPUT        tmpInput;
            List <INPUT> ins  = new List <INPUT>();
            string       text = "";

            if (e.Alt)
            {
                tmpInput            = new INPUT();
                tmpInput.type       = WindowsAPI.INPUT_KEYBOARD;
                tmpInput.ki.dwFlags = 0;
                tmpInput.ki.wScan   = (ushort)(WindowsAPI.VK_ALT & 0xff);
                ins.Add(tmpInput);
                text += "ALT +";
            }

            if (e.Shift)
            {
                tmpInput            = new INPUT();
                tmpInput.type       = WindowsAPI.INPUT_KEYBOARD;
                tmpInput.ki.dwFlags = 0;
                tmpInput.ki.wScan   = (ushort)(WindowsAPI.VK_LSHIFT & 0xff);
                ins.Add(tmpInput);
                text += "SHIFT +";
            }
            if (e.Control)
            {
                tmpInput            = new INPUT();
                tmpInput.type       = WindowsAPI.INPUT_KEYBOARD;
                tmpInput.ki.dwFlags = 0;
                tmpInput.ki.wScan   = (ushort)(WindowsAPI.VK_LCONTROL & 0xff);
                ins.Add(tmpInput);
                text += "CTRL +";
            }
            KeysConverter a = new KeysConverter();

            text += a.ConvertToInvariantString(e.KeyCode);
            ushort scanCode = (ushort)WindowsAPI.MapVirtualKey((ushort)e.KeyValue, 0);

            if (e.KeyCode == Keys.Menu || e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.ControlKey)
            {
                return;
            }
            tmpInput            = new INPUT();
            tmpInput.type       = WindowsAPI.INPUT_KEYBOARD;
            tmpInput.ki.dwFlags = 0;
            tmpInput.ki.wScan   = (ushort)(scanCode & 0xff);
            ins.Add(tmpInput);
            this.inputs   = ins.ToArray();
            textBox1.Text = text;
        }
コード例 #11
0
 private void Application_ApplicationExit(object sender, EventArgs e)
 {
     if (HotKey != null)
     {
         KeysConverter keyConv = new KeysConverter();
         Settings.Default.HotKey = keyConv.ConvertToInvariantString((Keys)HotKey?.KeyCombination);
     }
     else
     {
         Settings.Default.HotKey = null;
     }
     Settings.Default.Save();
     HotKey?.Dispose();
 }
コード例 #12
0
        public static string GetShortcutString(OPMShortcut cmd)
        {
            if (cmd >= OPMShortcut.CmdPlayPause && cmd < OPMShortcut.CmdOutOfRange)
            {
                KeysConverter kc = new KeysConverter();

                string actionKeys =
                    kc.ConvertToInvariantString(keyCommands[(int)cmd].KeyData);
                string altActionKeys =
                    kc.ConvertToInvariantString(altKeyCommands[(int)cmd].KeyData);

                if (actionKeys == altActionKeys)
                {
                    return(actionKeys);
                }
                else
                {
                    return(actionKeys + " " + Translator.Translate("TXT_OR") + " " + altActionKeys);
                }
            }

            return(string.Empty);
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: vovanovak/KeyLogger
    private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
    {
        if (counter > 0)
        {
            counter--;
        }
        else
        {
            counter = hooks.Count - 1;
            if ((nCode >= 0) && (wParam == (IntPtr)WM_KEYDOWN))
            {
                int           vkCode  = Marshal.ReadInt32(lParam);
                KeysConverter kc      = new KeysConverter();
                string        keyChar = kc.ConvertToInvariantString(vkCode);

                if ((Keys)vkCode == Keys.Shift)
                {
                    isShift = true;
                }
                if ((Keys)vkCode == Keys.Back)
                {
                    content = content.Remove(content.Length - 1, 1);
                }
                if ((Keys)vkCode == Keys.Enter)
                {
                    content = content.AppendLine();
                }
                if ((Keys)vkCode == Keys.CapsLock)
                {
                    if (isCapsLock == true)
                    {
                        isCapsLock = false;
                    }
                    else
                    {
                        isCapsLock = true;
                    }
                }
                if ((Keys)vkCode == Keys.Space)
                {
                    content = content.Append(' ');
                }
                else
                {
                    if (!isShift && !isCapsLock)
                    {
                        content = content.Append(char.ToLower(keyChar[0]));
                    }
                    else
                    if (isCapsLock && isShift)
                    {
                        content = content.Append(char.ToLower(keyChar[0]));
                        isShift = false;
                    }
                    else
                    {
                        content = content.Append(keyChar[0]);
                        isShift = false;
                    }
                }
                if (canWrite)
                {
                    canWrite = false;
                    System.IO.FileStream stream = System.IO.File.Open(fileName, System.IO.FileMode.Append);

                    stream.BeginWrite(Encoding.Default.GetBytes(content.ToString()), 0, Encoding.Default.GetByteCount(content.ToString().ToCharArray()), new AsyncCallback(delegate(IAsyncResult res)
                    {
                        stream.EndWrite(res);
                        stream.Close();
                        content.Clear();
                        canWrite = true;
                    }), null);
                }
                Console.Write(content.ToString());
                content.Clear();
            }
        }

        return(CallNextHookEx(hook, nCode, wParam, lParam));
    }
コード例 #14
0
        public void DisplayKeys()
        {
            try
            {
                User32.LockWindowUpdate(this.Handle);

                this.SuspendLayout();

                lvShortcuts.Items.Clear();

                List <OPMShortcut> shortcuts = new List <OPMShortcut>();
                for (OPMShortcut cmd = ShortcutMapper.CmdFirst; cmd < ShortcutMapper.CmdLast; cmd++)
                {
                    shortcuts.Add(cmd);
                }

                shortcuts.Sort(ShortcutsSorter);

                StringBuilder sb = new StringBuilder();

                foreach (OPMShortcut cmd in shortcuts)
                {
                    if (ShortcutMapper.IsHiddenShortcut(cmd))
                    {
                        continue;
                    }

                    string        cmdName = cmd.ToString();
                    string        desc    = Translator.Translate("TXT_" + cmdName.ToUpperInvariant());
                    KeysConverter kc      = new KeysConverter();
                    string        key     = kc.ConvertToInvariantString(ShortcutMapper.KeyCommands[(int)cmd].KeyData);
                    string        altKey  = kc.ConvertToInvariantString(ShortcutMapper.AltKeyCommands[(int)cmd].KeyData);

                    ListViewItem item = new ListViewItem(cmdName.Replace("Cmd", string.Empty));

                    OPMListViewSubItem subItemDesc   = new OPMListViewSubItem(item, desc);
                    OPMListViewSubItem subItemKey    = null;
                    OPMListViewSubItem subItemAltKey = null;

                    if (ShortcutMapper.IsConfigurableShortcut(cmd))
                    {
                        subItemKey    = new OPMListViewSubItem(_llEditKeys, item, key);
                        subItemAltKey = new OPMListViewSubItem(_llEditKeys, item, altKey);
                    }
                    else
                    {
                        subItemKey    = new OPMListViewSubItem(item, key);
                        subItemAltKey = new OPMListViewSubItem(item, altKey);
                    }

                    item.SubItems.Add(subItemDesc);
                    item.SubItems.Add(subItemKey);
                    item.SubItems.Add(subItemAltKey);


                    item.Tag = cmd;
                    lvShortcuts.Items.Add(item);

                    sb.AppendLine("<tr>");

                    sb.AppendLine("<td>");
                    sb.AppendLine(item.Text);
                    sb.AppendLine("</td>");

                    sb.AppendLine("<td>");
                    sb.AppendLine(subItemDesc.Text);
                    sb.AppendLine("</td>");

                    sb.AppendLine("<td>");
                    sb.AppendLine(subItemKey.Text);
                    sb.AppendLine("</td>");

                    sb.AppendLine("<td>");
                    sb.AppendLine(subItemAltKey.Text);
                    sb.AppendLine("</td>");

                    sb.AppendLine("<td>");
                    sb.AppendLine("Yes");
                    sb.AppendLine("</td>");

                    sb.AppendLine("</tr>");
                }

                this.ResumeLayout();
            }
            finally
            {
                User32.LockWindowUpdate(IntPtr.Zero);
            }
        }