Beispiel #1
0
 internal static bool OnKeyDown(System.Windows.Forms.Keys keyCode, uint repCount, bool prevState)
 {
     if (Phoenix.Runtime.RuntimeCore.Hotkeys.Contains(keyCode.ToString()))
     {
         if (!prevState)
         {
             Phoenix.Runtime.RuntimeCore.Hotkeys.Exec(keyCode.ToString());
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #2
0
    public static string VKeyToString(this System.Windows.Forms.Keys key)       // key to string..
    {
        string k = "";

        string keyname = key.ToString(); // built in translation..

        if (key == NumEnter)             // special treatement
        {
            return("NumEnter");
        }
        else if (keyname.Length == 2 && keyname[0] == 'D')          // remove the Dx
        {
            keyname = keyname.Substring(1);
        }
        else
        {
            Tuple <string, Keys> vk = (from t in oemtx where t.Item2 == key select t).FirstOrDefault();  // see if we have a table translate..

            if (vk != null)
            {
                keyname = vk.Item1;
            }
            else if (keyname.StartsWith("Oem"))                                                // oem tender care..
            {                                                                                  // just caps case it for niceness
                System.Globalization.TextInfo textInfo = new System.Globalization.CultureInfo("en-US", false).TextInfo;
                keyname = textInfo.ToTitleCase(keyname.Substring(keyname.Length > 4 ? 3 : 0)); // if its OemPeriod, use Period. if its Oem1, use Oem1
            }
        }


        return(k + keyname);
    }
Beispiel #3
0
    public bool Register(System.Windows.Forms.Keys key, bool alt, bool ctrl, bool shift, bool win)
    {
        if (this.IsRegistered)
        {
            this.Unregister();
        }

        _modifierALT   = alt;
        _modifierCTRL  = ctrl;
        _modifierSHIFT = shift;
        _modifierWIN   = win;
        _key           = key.ToString();


        //Dim keyAlt As Keys = (key And Keys.Alt)
        //Dim keyControl As Keys = (key And Keys.Control)
        //Dim keyShift As Keys = (key And Keys.Shift)

        uint Modifiers = 0;

        if (alt)
        {
            Modifiers += NativeMethods.MOD_ALT;
        }
        if (ctrl)
        {
            Modifiers += NativeMethods.MOD_CONTROL;
        }
        if (shift)
        {
            Modifiers += NativeMethods.MOD_SHIFT;
        }
        if (win)
        {
            Modifiers += NativeMethods.MOD_WIN;
        }
        //If (keyAlt = Keys.Alt) Then modValue += NativeMethods.MOD_ALT
        //If (keyControl = Keys.Control) Then modValue += NativeMethods.MOD_CONTROL
        //If (keyShift = Keys.Shift) Then modValue += NativeMethods.MOD_SHIFT
        uint keyValue = Convert.ToUInt32(key);

        //- CUInt(keyAlt) - CUInt(keyControl) - CUInt(keyShift)

        this._Window = new HotkeyWindow();
        this._Window.CreateHandle(new CreateParams());
        this._Window.HotkeyMessage += Window_HotkeyMessage;

        if (NativeMethods.RegisterHotKey(this._Window.Handle, _ID, Modifiers, keyValue) == 0)
        {
            MessageBox.Show(HotKeyString() + Convert.ToString(" hotkey is already registered."));
            return(false);
            //Environment.[Exit](0)
        }
        else
        {
            _IsRegistered = true;
            return(true);
        }
        //Me._IsRegistered = Not (NativeMethods.RegisterHotKey(Me._Window.Handle, _ID, modValue, keyValue) = 0)
    }
Beispiel #4
0
        public override string ToString()
        {
            switch (type)
            {
            case "Key press":
                return("Key press : " + keys.ToString());

            case "Key hold":
                return("Key hold: " + keys.ToString());

            case "Key release":
                return("Key release: " + keys.ToString());

            case "Timer":
                return("Timer : " + timer.ToString() + " secs");

            default:
                return("Error : Unknown event");
            }
        }
Beispiel #5
0
        public static Key Convert(SWF.Keys key)
        {
            var keys = key.ToString()
                       .Split(new[] { ", " }, StringSplitOptions.None)
                       .Select(v => (SWF.Keys)Enum.Parse(typeof(SWF.Keys), v));
            Key ret = Key.None;

            foreach (var val in keys)
            {
                ret |= Find(val);
            }
            return(ret);
        }
 public static string ToKeyString(this System.Windows.Forms.Keys keycode) {
     //switch(keycode) {
     //    default:
     //        return keycode.ToString();
     //}
     var str = keycode.ToString();
     if(str.StartsWith("Oem")) {
         return str["Oem".Length].ToString().ToUpper() + str.Substring("Oem".Length + 1);
     }
     else {
         return str;
     }
 }
Beispiel #7
0
        static string convert(System.Windows.Forms.Keys e)
        {
            int keyValue = (int)e;

            if (e == Keys.Space)
            {
                return(" ");
            }
            if ((keyValue >= 0x30 && keyValue <= 0x39) // numbers

                )                                      // numpad
            {
                return(e.ToString().Replace("D", ""));
            }

            if ((keyValue >= 0x30 && keyValue <= 0x39) || // numbers
                (keyValue >= 0x41 && keyValue <= 0x5A) // letters
                                                       //|| (keyValue >= 0x60 && keyValue <= 0x69)
                )                                      // numpad
            {
                return(e.ToString());
            }
            return("");
        }
Beispiel #8
0
        private string GetHotKeyName(Forms.Keys key)
        {
            funKeys.Sort();

            var sb = new System.Text.StringBuilder();

            foreach (var item in funKeys)
            {
                sb.Append(GetkeyflagShowName(item));
                sb.Append("+");
            }

            sb.Append(key.ToString());

            return(sb.ToString());
        }
Beispiel #9
0
        public override string ToString()
        {
            List <string> keys = new List <string>();

            if (CTRL)
            {
                keys.Add("CTRL");
            }
            if (ALT)
            {
                keys.Add("ALT");
            }

            keys.Add(Key.ToString());

            return($"(Shortcut: {string.Join(" + ", keys)})");
        }
        public void SetMenuShortcuts(string menuFullName, System.Windows.Forms.Keys keyData)
        {
            if (!m_menuDictionary.ContainsKey(menuFullName))
            {
                throw new NotImplementedException(@"Can not find the menu name :" + menuFullName + @" when add a shortcuts !");
            }

            if (m_menuFullNameMapKeys.ContainsValue(keyData))
            {
                throw new NotImplementedException(@"The shortcuts named :" + keyData.ToString() + " has been used !");
            }

            ToolStripMenuItem menu = m_menuDictionary[menuFullName];

            menu.ShortcutKeys     = keyData;
            menu.ShowShortcutKeys = true;
            m_menuFullNameMapKeys.Add(menuFullName, keyData);
        }
Beispiel #11
0
        /// <summary>
        /// 返回表示对象的字符串
        /// </summary>
        /// <returns>字符串</returns>
        public override string ToString()
        {
            StringBuilder str = new StringBuilder();

            if (_Control)
            {
                str.Append("Control ");
            }
            if (_Shift)
            {
                str.Append("Shift ");
            }
            if (_Alt)
            {
                str.Append("Alt ");
            }
            str.Append(_Key.ToString());
            return(str.ToString());
        }
Beispiel #12
0
        /// <summary>
        /// Create a list view item describing this HidEvent
        /// </summary>
        /// <returns></returns>
        public ListViewItem ToListViewItem()
        {
            string usageText   = "";
            string inputReport = null;

            foreach (ushort usage in Usages)
            {
                if (usageText != "")
                {
                    //Add a separator
                    usageText += ", ";
                }

                //Try to get a name for that usage
                string name = "";
                if (Enum.IsDefined(typeof(Hid.UsagePage), UsagePage))
                {
                    UsagePage usagePage = (UsagePage)UsagePage;

                    try
                    {
                        name = Enum.GetName(Utils.UsageType(usagePage), usage);
                    }
                    catch
                    {
                    }
                }

                if (name == null || name.Equals("") || Device.IsGamePad) //Gamepad buttons do not belong to Usage enumeration, they are just ordinal
                {
                    name = usage.ToString("X2");
                }
                usageText += name;
            }

            // Get input report for generic HID events
            if (IsGeneric)
            {
                inputReport = InputReportString();
            }

            //If we are a gamepad display axis and dpad values
            if (Device != null && Device.IsGamePad)
            {
                //uint dpadUsageValue = GetUsageValue((ushort)Hid.UsagePage.GenericDesktopControls, (ushort)Hid.Usage.GenericDesktop.HatSwitch);
                //usageText = dpadUsageValue.ToString("X") + " (dpad), " + usageText;

                if (usageText != "")
                {
                    //Add a separator
                    usageText += " (Buttons)";
                }

                if (usageText != "")
                {
                    //Add a separator
                    usageText += ", ";
                }

                usageText += GetDirectionPadState().ToString();

                //For each axis
                foreach (KeyValuePair <HIDP_VALUE_CAPS, uint> entry in UsageValues)
                {
                    if (entry.Key.IsRange)
                    {
                        continue;
                    }

                    //Get our usage type
                    Type usageType = Utils.UsageType((UsagePage)entry.Key.UsagePage);
                    if (usageType == null)
                    {
                        //Unknown usage type
                        //TODO: check why this is happening on Logitech rumble gamepad 2.
                        //Probably some of our axis are hiding in there.
                        continue;
                    }

                    //Get the name of our axis
                    string name = Enum.GetName(usageType, entry.Key.NotRange.Usage);

                    if (usageText != "")
                    {
                        //Add a separator
                        usageText += ", ";
                    }
                    usageText += entry.Value.ToString("X") + " (" + name + ")";
                }
            }
            //Handle keyboard events
            else if (IsKeyboard)
            {
                //Get the virtual key
                System.Windows.Forms.Keys vKey = (Keys)RawInput.keyboard.VKey;
                usageText = vKey.ToString() + " -";

                //Get the key flag
                if (IsButtonUp)
                {
                    usageText += " UP";
                }
                else if (IsButtonDown)
                {
                    usageText += " DOWN";
                }

                if (RawInput.keyboard.Flags.HasFlag(RawInputKeyFlags.RI_KEY_E0))
                {
                    usageText += " E0";
                }

                if (RawInput.keyboard.Flags.HasFlag(RawInputKeyFlags.RI_KEY_E1))
                {
                    usageText += " E1";
                }

                if (HasModifierShift)
                {
                    usageText += " SHIFT";
                }

                if (HasModifierControl)
                {
                    usageText += " CTRL";
                }

                if (HasModifierAlt)
                {
                    usageText += " ALT";
                }

                if (HasModifierWindows)
                {
                    usageText += " WIN";
                }


                //Put our scan code into our input report field
                inputReport = "0x" + RawInput.keyboard.MakeCode.ToString("X4");
            }

            //Now create our list item
            ListViewItem item = new ListViewItem(new[] { usageText, inputReport, UsagePageNameAndValue(), UsageCollectionNameAndValue(), RepeatCount.ToString(), Time.ToString("HH:mm:ss:fff"), IsBackground.ToString() });

            return(item);
        }
        /// <summary>
        /// Returns friendly name of given Forms <see cref="forms.Keys"/>.
        /// </summary>
        /// <param name="key">Forms <see cref="forms.Keys"/>.</param>
        public static string GetFriendlyName(forms.Keys key)
        {
            if (!Enum.IsDefined(typeof(forms.Keys), key))
            {
                return("None");
            }

            int value = (int)key;

            if (48 < value && value < 58)
            {
                return((value - 48).ToString());
            }

            switch (value)
            {
            case 48: return("0");

            case 13: return("Enter");

            case 20: return("CapsLock");

            case 33: return("PageUp");

            case 34: return("PageDown");

            case 44: return("PrintScreen");

            case 192: return("~");

            case 219: return("[");

            case 220: return(@"\");

            case 221: return("]");

            case 222: return("\"");

            case 226: return(@"\");

            case 191: return("?");

            case 107: return("NumPadPlus");

            case 8: return("Backspace");

            case 110: return("NumPadPeriod");

            case 111: return("NumPadSlash");

            case 40: return("DownArrow");

            case 162: return("LeftCtrl");

            case 37: return("LeftArrow");

            case 164: return("LeftAlt");

            case 160: return("LeftShift");

            case 38: return("UpArrow");

            case 39: return("RightArrow");

            case 18: return("Alt");

            case 186: return(";");

            case 189: return("-");

            case 187: return("+");

            case 188: return(",");

            case 190: return(".");

            case 109: return("NumPadMinus");

            case 106: return("NumPadStar");

            case 165: return("RightAlt");

            case 163: return("RightCtrl");

            case 161: return("RightShift");
            }

            return(key.ToString());
        }
 private String VKeyToChar(int keyCode)
 {
     WinForms.Keys key = (WinForms.Keys)keyCode;
     return(key.ToString());
 }