void HandleSetTextHotkey() { string label = reader.ReadString(); string action = reader.ReadString(); int keyCode = reader.ReadInt32(); byte keyMods = reader.ReadUInt8(); #if !ANDROID if (keyCode < 0 || keyCode > 255) { return; } Key key = LwjglToKey.Map[keyCode]; if (key == Key.None) { return; } Utils.LogDebug("CPE Hotkey added: " + key + "," + keyMods + " : " + action); if (action.Length == 0) { HotkeyList.Remove(key, keyMods); } else if (action[action.Length - 1] == '◙') // graphical form of \n { action = action.Substring(0, action.Length - 1); HotkeyList.Add(key, keyMods, action, false); } else // more input needed by user { HotkeyList.Add(key, keyMods, action, true); } #endif }
void SaveChangesClick(Game game, Widget widget) { if (origHotkey.Trigger != Key.None) { HotkeyList.Remove(origHotkey.Trigger, origHotkey.Flags); HotkeyList.UserRemovedHotkey(origHotkey.Trigger, origHotkey.Flags); } MenuInputWidget input = (MenuInputWidget)widgets[actionI]; if (curHotkey.Trigger != Key.None) { HotkeyList.Add(curHotkey.Trigger, curHotkey.Flags, input.Text.ToString(), curHotkey.StaysOpen); HotkeyList.UserAddedHotkey(curHotkey.Trigger, curHotkey.Flags, curHotkey.StaysOpen, input.Text.ToString()); } game.Gui.SetNewScreen(new HotkeyListScreen(game)); }
public HotkeyStatus RegisterHotkey(Keys hotkey, Action hotkeyPress = null, int tag = 0) { KeyInfo keyInfo = new KeyInfo(hotkey); if (keyInfo.KeyCode == Keys.None) { return(HotkeyStatus.NotConfigured); } if (IsHotkeyExist(hotkey)) { DebugHelper.WriteLine("Hotkey already exist: " + keyInfo); return(HotkeyStatus.Failed); } string atomName = Thread.CurrentThread.ManagedThreadId.ToString("X8") + (int)hotkey; ushort id = NativeMethods.GlobalAddAtom(atomName); if (id == 0) { DebugHelper.WriteLine("Unable to generate unique hotkey ID. Error code: " + Marshal.GetLastWin32Error()); return(HotkeyStatus.Failed); } if (!NativeMethods.RegisterHotKey(Handle, (int)id, (uint)keyInfo.ModifiersEnum, (uint)keyInfo.KeyCode)) { NativeMethods.GlobalDeleteAtom(id); DebugHelper.WriteLine("Unable to register hotkey: {0}\r\nError code: {1}", keyInfo, Marshal.GetLastWin32Error()); return(HotkeyStatus.Failed); } HotkeyInfo hotkeyInfo = new HotkeyInfo(id, hotkey, hotkeyPress, tag); HotkeyList.Add(hotkeyInfo); return(HotkeyStatus.Registered); }