コード例 #1
0
        private int HookProc(int code, IntPtr wParam, ref KeyboardLLHookStruct lParam)
        {
            if (code == HC_ACTION)
            {
                if (wParam.ToInt32() == WM_KEYDOWN || wParam.ToInt32() == WM_SYSKEYDOWN)
                {
                    foreach (var item in _menuItems)
                    {
                        var key1 = true;
                        var key2 = true;

                        if (item.Key1 != VirtualKeyModifier.None)
                        {
                            var key1State = GetAsyncKeyState((int)item.Key1) & 0x8000;
                            key1 = Convert.ToBoolean(key1State);
                        }

                        if (item.Key2 != VirtualKeyModifier.None)
                        {
                            var key2State = GetAsyncKeyState((int)item.Key2) & 0x8000;
                            key2 = Convert.ToBoolean(key2State);
                        }

                        if (key1 && key2 && lParam.vkCode == (int)item.Key3)
                        {
                            var handler = Hooked;
                            if (handler != null)
                            {
                                var menuItemId = MenuItemId.GetId(item.Name);
                                var eventArgs  = new HotKeyEventArgs(menuItemId);
                                handler.BeginInvoke(this, eventArgs, null, null);
                                break;
                            }
                        }
                    }
                }
            }

            return(CallNextHookEx(_hookHandle, code, wParam, ref lParam));
        }
コード例 #2
0
        private void FillGridViewHotKeys(DataGridView gridView, IList <Settings.MenuItem> items, LanguageSettings languageSettings)
        {
            gridView.Tag = items;
            foreach (var item in items)
            {
                if (item.Type == MenuItemType.Item)
                {
                    var index = gridView.Rows.Add();
                    var row   = gridView.Rows[index];
                    var id    = MenuItemId.GetId(item.Name);
                    var title = GetTransparencyTitle(id, languageSettings);
                    title              = title != null ? title : languageSettings.GetValue(item.Name);
                    row.Tag            = item;
                    row.Cells[0].Value = title;
                    row.Cells[1].Value = item == null ? "" : item.ToString();
                    ((DataGridViewCheckBoxCell)row.Cells[2]).Value       = item.Show;
                    ((DataGridViewCheckBoxCell)row.Cells[2]).ToolTipText = languageSettings.GetValue("clm_hotkeys_show_tooltip");
                }

                if (item.Type == MenuItemType.Separator)
                {
                    var index = gridView.Rows.Add();
                    var row   = gridView.Rows[index];
                    var title = languageSettings.GetValue("separator");
                    row.Tag            = item;
                    row.Cells[0].Value = title;
                    row.Cells[1].Value = item == null ? "" : item.ToString();
                    ((DataGridViewCheckBoxCell)row.Cells[2]).Value       = item.Show;
                    ((DataGridViewCheckBoxCell)row.Cells[2]).ToolTipText = languageSettings.GetValue("clm_hotkeys_show_tooltip");
                }

                if (item.Type == MenuItemType.Group)
                {
                    var index = gridView.Rows.Add();
                    var row   = gridView.Rows[index];
                    row.Tag            = item;
                    row.Cells[0].Value = languageSettings.GetValue(item.Name);
                    row.ReadOnly       = true;
                    ((DataGridViewCheckBoxCell)row.Cells[2]).Value        = item.Show;
                    ((DataGridViewCheckBoxCell)row.Cells[2]).ToolTipText  = languageSettings.GetValue("clm_hotkeys_show_tooltip");
                    ((DataGridViewDisableButtonCell)row.Cells[3]).Enabled = false;

                    foreach (var subItem in item.Items)
                    {
                        if (subItem.Type == MenuItemType.Item)
                        {
                            var subItemIndex = gridView.Rows.Add();
                            var subItemRow   = gridView.Rows[subItemIndex];
                            var id           = MenuItemId.GetId(subItem.Name);
                            var title        = GetTransparencyTitle(id, languageSettings);
                            title                     = title != null ? title : languageSettings.GetValue(subItem.Name);
                            subItemRow.Tag            = subItem;
                            subItemRow.Cells[0].Value = title;
                            subItemRow.Cells[1].Value = subItem == null ? "" : subItem.ToString();
                            ((DataGridViewCheckBoxCell)subItemRow.Cells[2]).Value       = subItem.Show;
                            ((DataGridViewCheckBoxCell)subItemRow.Cells[2]).ToolTipText = languageSettings.GetValue("clm_hotkeys_show_tooltip");
                            var padding = subItemRow.Cells[0].Style.Padding;
                            subItemRow.Cells[0].Style.Padding = new Padding(20, padding.Top, padding.Right, padding.Bottom);
                        }

                        if (subItem.Type == MenuItemType.Separator)
                        {
                            var subItemIndex = gridView.Rows.Add();
                            var subItemRow   = gridView.Rows[subItemIndex];
                            var title        = languageSettings.GetValue("separator");
                            subItemRow.Tag            = subItem;
                            subItemRow.Cells[0].Value = title;
                            subItemRow.Cells[1].Value = subItem == null ? "" : subItem.ToString();
                            ((DataGridViewCheckBoxCell)subItemRow.Cells[2]).Value       = subItem.Show;
                            ((DataGridViewCheckBoxCell)subItemRow.Cells[2]).ToolTipText = languageSettings.GetValue("clm_hotkeys_show_tooltip");
                            var padding = subItemRow.Cells[0].Style.Padding;
                            subItemRow.Cells[0].Style.Padding = new Padding(20, padding.Top, padding.Right, padding.Bottom);
                        }
                    }
                }
            }
        }