public static UsedToSaveProgramSetv2 Read(System.IO.Stream stream) { IFormatter formatter = new BinaryFormatter(); int version = (Int32)formatter.Deserialize(stream); if (version == 1) { //This is a version 1 file Convert it to a Version 2 file UsedToSaveProgramSet prgramsetv1 = (UsedToSaveProgramSet)formatter.Deserialize(stream); List <KeyMap> TempKeys = new List <KeyMap>(); String[] TempMacros = new String[kMaxKeys]; UsedToSaveProgramSetv2 programset = new UsedToSaveProgramSetv2(TempKeys); for (int i = 0; i < kMaxKeys; i++) { //process each of the keys int offset = (i) * 3; KeyMap NewKey = new KeyMap(); NewKey.Dx1Key = (byte)(i + 1); offset++; NewKey.Type = prgramsetv1.keyMap[offset++]; NewKey.Action = prgramsetv1.keyMap[offset++]; if (NewKey.Action == (byte)0) { NewKey.Description = "Unassigned"; } else { NewKey.Description = "Keycode-" + NewKey.Action.ToString(); } programset.keyMaps.Add(NewKey); } TempMacros = prgramsetv1.macroMap; for (int i = 0; i < kMaxKeys; i++) { //Process each of the Macros into the corresponding key if (TempMacros[i] != null) { programset.keyMaps[i].MacroName = TempMacros[i]; } } return(programset); } UsedToSaveProgramSetv2 programSet = (UsedToSaveProgramSetv2)formatter.Deserialize(stream); return(programSet); }
} //}}} private static string KeyMap_ToXML(KeyMap keyMap) //{{{ { return(" <" + XMLTAG_KEYMAP + ">" + " <" + XMLTAG_KEYINDX + ">" + string.Format("{0,2}", keyMap.KeyNum) + "</" + XMLTAG_KEYINDX + ">" + " <" + XMLTAG_KEYCODE + ">" + string.Format("{0,3}", keyMap.KeyCode) + "</" + XMLTAG_KEYCODE + ">" + " <" + XMLTAG_KEYTYPE + ">" + string.Format("{0,2}", keyMap.KeyType) + "</" + XMLTAG_KEYTYPE + ">" + " <" + XMLTAG_KEYNAME + ">" + string.Format("{0,10}", keyMap.KeyName) + "</" + XMLTAG_KEYNAME + ">" + " <" + XMLTAG_KEYDESC + ">" + string.Format("{0,10}", keyMap.KeyDesc) + "</" + XMLTAG_KEYDESC + ">" + " <" + XMLTAG_MACNAME + ">" + string.Format("{0,10}", keyMap.MacName) + "</" + XMLTAG_MACNAME + ">" + " <" + XMLTAG_MAPDATA + ">" + string.Format("{0,2}", keyMap.KeyData) + "</" + XMLTAG_MAPDATA + ">" + " </" + XMLTAG_KEYMAP + ">" ); }
// }}} public void KeyUp(KeyMap CurrentKey, string ExtraData = "") // SPECIAL KEY {{{ { KMH_INPUT input_up = new KMH_INPUT(); switch (CurrentKey.KeyCode) { case 0: // Left Mouse Button {{{ //mouse_event(0x04, 0, 0, 0, 0); input_up.type = INPUT_MOUSE; input_up.mi.dx = 0; input_up.mi.dy = 0; input_up.mi.mouseData = 0; input_up.mi.dwFlags = (int)MOUSEEVENTF_LEFTUP; break; //}}} case 1: // Right Mouse Button {{{ input_up.type = INPUT_MOUSE; input_up.mi.dx = 0; input_up.mi.dy = 0; input_up.mi.mouseData = 0; input_up.mi.dwFlags = (int)MOUSEEVENTF_RIGHTUP; break; //}}} case 2: // Middle Mouse Button {{{ input_up.type = INPUT_MOUSE; input_up.mi.dx = 0; input_up.mi.dy = 0; input_up.mi.mouseData = 0; input_up.mi.dwFlags = (int)MOUSEEVENTF_MIDDLEUP; break; //}}} default: // Special-Key that can be sent just with the SpecialValue to the Keyboard Input {{{ input_up.type = INPUT_KEYBOARD; input_up.ki.wVk = _SpecialKeys[CurrentKey.KeyCode].SpecialValue; input_up.ki.wScan = 0; input_up.ki.dwExtraInfo = IntPtr.Zero; input_up.ki.dwFlags = KEYEVENTF_KEYUP; break; //}}} } KMH_INPUT[] inputs = { input_up }; NativeMethods.SendInput(1, inputs, Marshal.SizeOf(input_up)); }
} //}}} // KEYS #region keyMapList {{{ private void init_keyMapList() //{{{ { keyMapList = new List <KeyMap>(); for (int keyNum = 1; keyNum <= Globals.KEYS_MAX; ++keyNum) { KeyMap keyMap = new KeyMap(); keyMap.KeyCode = 0; keyMap.KeyDesc = "Unassigned"; keyMap.KeyNum = (byte)(keyNum); keyMapList.Add(keyMap); } } //}}}
private void InitKeyMap(ref List <KeyMap> KeyMaps) { //Default Key Map int TempKey; //Clear current KeyMap if any KeyMaps = new List <KeyMap>(); for (int i = 0; i < kMaxKeys; i++) { TempKey = i + 1; KeyMap NewKey = new KeyMap(); NewKey.Dx1Key = (byte)(TempKey); NewKey.Action = 0; NewKey.Action = 0; NewKey.Description = "Unassigned"; KeyMaps.Add(NewKey); } }
} //}}} public void initKeyMap(byte keyIndex) //{{{ { string caller = "initKeyMap"; KeyMap keyMap = keyMapList[keyIndex]; keyProgrammer.notify_keyMap_KEY_CLEARED(); keyMap.KeyCode = 0; keyMap.KeyData = ""; keyMap.KeyDesc = "Unassigned"; keyMap.KeyName = "--"; keyMap.KeyType = 0; keyMap.MacName = ""; if (DX1Utility.Debug) { log(caller + ": " + keyProgrammer.KeyMap_changeToCommit); } } //}}}
public void InitKeyProperties(KeyMap CurrentKey) { //Assign the CurrentKeyMap to the entire KeyMap passed in CurrentKeyMap = CurrentKey; KeysConverter KC = new KeysConverter(); //Go straight to the Confimation Page and populate it TB_Wizard.SelectedIndex = 6; T_Conf_Type.Text = sKeyBindings[CurrentKeyMap.Type]; T_Conf_Desc.Text = CurrentKeyMap.Description; T_Conf_Actual.Text = CurrentKeyMap.Action.ToString(); T_Conf_Desc.Focus(); T_Conf_Type.Enabled = false; T_Conf_Actual.Enabled = false; B_Back.Enabled = false; B_Next.Enabled = false; B_OK.Enabled = true; BuildMacroList(); }
public void KeyUp(KeyMap CurrentKey, string ExtraData = "") { //A special key has been released //Determine the type of Special Key being pressed //Added for Issue #19 switch (CurrentKey.Type) { case 4: { //4 = Special Key (Mouse, Media, etc) switch (CurrentKey.Action) { case 0: { //Left Mouse Button //mouse_event(0x04, 0, 0, 0, 0); INPUT input_up = new INPUT(); input_up.type = INPUT_MOUSE; input_up.mi.dx = 0; input_up.mi.dy = 0; input_up.mi.mouseData = 0; input_up.mi.dwFlags = (int)MOUSEEVENTF_LEFTUP; INPUT[] input = { input_up }; SendInput(1, input, Marshal.SizeOf(input_up)); break; } case 1: { //Right Mouse Button INPUT input_up = new INPUT(); input_up.type = INPUT_MOUSE; input_up.mi.dx = 0; input_up.mi.dy = 0; input_up.mi.mouseData = 0; input_up.mi.dwFlags = (int)MOUSEEVENTF_RIGHTUP; INPUT[] input = { input_up }; SendInput(1, input, Marshal.SizeOf(input_up)); break; } case 2: { //Middle Mouse Button INPUT input_up = new INPUT(); input_up.type = INPUT_MOUSE; input_up.mi.dx = 0; input_up.mi.dy = 0; input_up.mi.mouseData = 0; input_up.mi.dwFlags = (int)MOUSEEVENTF_MIDDLEUP; INPUT[] input = { input_up }; SendInput(1, input, Marshal.SizeOf(input_up)); break; } default: { //Used for any Special Key that can be sent just with the SpecialValue to the Keyboard Input INPUT input_up = new INPUT(); input_up.type = INPUT_KEYBOARD; input_up.ki.wVk = _SpecialKeys[CurrentKey.Action].SpecialValue; input_up.ki.wScan = 0; input_up.ki.dwExtraInfo = IntPtr.Zero; input_up.ki.dwFlags = KEYEVENTF_KEYUP; INPUT[] input = { input_up }; SendInput(1, input, Marshal.SizeOf(input_up)); break; } } break; } case 5: { //5 = Toggle Key //Added for Issue #19 switch (Bags.getValue(CurrentKey.Action)) { case 1: { //One Key-up has already been ignored, take this one and release the Key INPUT input_down = new INPUT(); input_down.type = INPUT_KEYBOARD; input_down.ki.wVk = CurrentKey.Action; input_down.ki.wScan = 0; input_down.ki.dwExtraInfo = IntPtr.Zero; input_down.ki.dwFlags = KEYEVENTF_KEYUP; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); //Remove Key being "pressed" from Dictionary so it isn't released again later Bags.RemoveToggle(CurrentKey.Action); DebugLog.Instance.writeLog(" Key Upped: " + CurrentKey.Action); break; } case 2: { //Key just pressed ignore this key-up, change State to 1 Bags.DecValue(CurrentKey.Action); DebugLog.Instance.writeLog(" First Key Up ignored: " + CurrentKey.Action); break; } default: { //Should never hit here. DebugLog.Instance.writeLog(" Unknown State for key: " + CurrentKey.Action); break; } } break; } default: { break; } } }
//[System.Runtime.InteropServices.DllImport("user32.dll")] //public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); public void KeyDown(KeyMap CurrentKey, string ExtraData = "") { //A special key has been pressed //Determine the type of Special Key being pressed //Added for Issue #19 switch (CurrentKey.Type) { case 4: { //4 = Special Key (Mouse, Media, etc) switch (CurrentKey.Action) { case 0: { //Left Mouse Button //Old Code - Mostly Worked //mouse_event(0x02, 0, 0, 0, 0); INPUT input_down = new INPUT(); input_down.type = INPUT_MOUSE; input_down.mi.dx = 0; input_down.mi.dy = 0; input_down.mi.mouseData = 0; input_down.mi.dwFlags = (int)MOUSEEVENTF_LEFTDOWN; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } case 1: { //Right Mouse Button INPUT input_down = new INPUT(); input_down.type = INPUT_MOUSE; input_down.mi.dx = 0; input_down.mi.dy = 0; input_down.mi.mouseData = 0; input_down.mi.dwFlags = (int)MOUSEEVENTF_RIGHTDOWN; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } case 2: { //Middle Mouse Button INPUT input_down = new INPUT(); input_down.type = INPUT_MOUSE; input_down.mi.dx = 0; input_down.mi.dy = 0; input_down.mi.mouseData = 0; input_down.mi.dwFlags = (int)MOUSEEVENTF_MIDDLEDOWN; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } case 3: { //Mouse Vert Scroll INPUT input_down = new INPUT(); input_down.type = INPUT_MOUSE; input_down.mi.dx = 0; input_down.mi.dy = 0; //Check to see if scrolling Up or down if (CurrentKey.CustomData == "1") input_down.mi.mouseData = 100; else input_down.mi.mouseData = -100; input_down.mi.dwFlags = (int)MOUSEEVENTF_VWHEEL; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } case 4: { //Mouse Horz Scroll INPUT input_down = new INPUT(); input_down.type = INPUT_MOUSE; input_down.mi.dx = 0; input_down.mi.dy = 0; //Check to see if scrolling Up or down if (CurrentKey.CustomData == "1") input_down.mi.mouseData = 100; else input_down.mi.mouseData = -100; input_down.mi.dwFlags = (int)MOUSEEVENTF_HWHEEL; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } //case 5: // { // //Media Play/Pause // INPUT input_down = new INPUT(); // input_down.ki.wVk = (ushort)MEDIA_PLAY_PAUSE; // input_down.ki.wScan = 0; // input_down.ki.dwExtraInfo = IntPtr.Zero; // input_down.ki.dwFlags = 0; // INPUT[] input = { input_down }; // SendInput(1, input, Marshal.SizeOf(input_down)); // break; // } default: { //Used for any Special Key that can be sent just with the SpecialValue to the Keyboard Input INPUT input_down = new INPUT(); input_down.type = INPUT_KEYBOARD; input_down.ki.wVk = _SpecialKeys[CurrentKey.Action].SpecialValue; input_down.ki.wScan = 0; input_down.ki.dwExtraInfo = IntPtr.Zero; input_down.ki.dwFlags = 0; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } } break; } case 5: { //5 = Toggle Key //Added for Issue #19 DebugLog.Instance.writeLog("Attempting to Toggle key: " + CurrentKey.Action, true); //Check if Key is "0", if so press key (Ignore key in all other states) if (Bags.getValue(CurrentKey.Action) == 0) { INPUT input_down = new INPUT(); input_down.type = INPUT_KEYBOARD; input_down.ki.wVk = CurrentKey.Action; input_down.ki.wScan = 0; input_down.ki.dwExtraInfo = IntPtr.Zero; input_down.ki.dwFlags = 0; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); //Set Flag to "ON" //Add Key being "pressed" to Dictionary for later removal Bags.AddToggle(CurrentKey.Action, 2); DebugLog.Instance.writeLog(" Key Toggled: " + CurrentKey.Action); } else { DebugLog.Instance.writeLog(" Key NOT Toggled: " + CurrentKey.Action); } break; } default: { break; } } }
private void InitKeyMap(ref List<KeyMap> KeyMaps) { //Default Key Map int TempKey; //Clear current KeyMap if any KeyMaps = new List<KeyMap>(); for (int i = 0; i < kMaxKeys; i++ ) { TempKey = i+1; KeyMap NewKey = new KeyMap(); NewKey.Dx1Key = (byte)(TempKey); NewKey.Action = 0; NewKey.Action = 0; NewKey.Description = "Unassigned"; KeyMaps.Add(NewKey); } }
public static UsedToSaveProgramSetv2 Read(System.IO.Stream stream) { IFormatter formatter = new BinaryFormatter(); int version = (Int32)formatter.Deserialize(stream); if (version == 1) { //This is a version 1 file Convert it to a Version 2 file UsedToSaveProgramSet prgramsetv1 = (UsedToSaveProgramSet)formatter.Deserialize(stream); List<KeyMap> TempKeys = new List<KeyMap>(); String[] TempMacros = new String[kMaxKeys]; UsedToSaveProgramSetv2 programset = new UsedToSaveProgramSetv2(TempKeys); for (int i = 0; i < kMaxKeys; i++) { //process each of the keys int offset = (i) * 3; KeyMap NewKey = new KeyMap(); NewKey.Dx1Key = (byte)(i+1); offset++; NewKey.Type = prgramsetv1.keyMap[offset++]; NewKey.Action = prgramsetv1.keyMap[offset++]; if (NewKey.Action == (byte)0) { NewKey.Description = "Unassigned"; } else { NewKey.Description = "Keycode-" + NewKey.Action.ToString(); } programset.keyMaps.Add(NewKey); } TempMacros = prgramsetv1.macroMap; for (int i = 0; i < kMaxKeys; i++) { //Process each of the Macros into the corresponding key if (TempMacros[i] != null) { programset.keyMaps[i].MacroName = TempMacros[i]; } } return programset; } UsedToSaveProgramSetv2 programSet = (UsedToSaveProgramSetv2)formatter.Deserialize(stream); return programSet; }
} //}}} public static void sync_colors() //{{{ { // CURRENT KEY {{{ KeyMap keyMap = (profile.keyProgrammer.KeyNum > 0) ? profile.keyMapList[profile.keyProgrammer.KeyNum - 1] : ui.CurrentKeyMap; if (ui.ShutDown_Requested) { ui.T_Description.Text = "SHUTDOWN"; ui.T_SingleKey.Text = profile.CurrentProfileName; ui.T_Conf_Code.Text = ""; ui.T_Conf_Type.Text = ""; } else { if (keyMap.TypeToString() != "") { ui.T_Description.Text = keyMap.KeyDesc; ui.T_SingleKey.Text = keyMap.KeyName; ui.T_Conf_Code.Text = keyMap.KeyCode.ToString(); ui.T_Conf_Type.Text = keyMap.TypeToString(); } else { ui.T_Description.Text = ""; ui.T_SingleKey.Text = ""; ui.T_Conf_Code.Text = ""; ui.T_Conf_Type.Text = ""; } } //}}} // SHUTDOWN {{{ if (ui.ShutDown_Requested) { ui.BackColor = UI_GRAY; ui.ForeColor = UI_WHITE; /*{{{ * ui.B_ShutDown .ForeColor = UI_WHITE; * ui.B_KeyProgrammer.ForeColor = UI_WHITE; * ui.G_DX1_KEYS .ForeColor = UI_WHITE; * }}}*/ ui.G_DX1_KEYS.CurrentCell = null; } //}}} // PENDING COMMITS {{{ else { // COLORS: {{{ bool keyMap_to_commit = (profile.keyProgrammer.KeyMap_changeToCommit != ""); bool profile_to_commit = (profile.keyProgrammer.Profile_changeToCommit != ""); bool keyMap_and_profile_to_commit = keyMap_to_commit && profile_to_commit; Color border_color = keyMap_and_profile_to_commit ? Color.Magenta : keyMap_to_commit ? Color.Red : profile_to_commit ? Color.Blue : ui.C4_Exit_onClose.Checked ? Color.White : Color.Green ; Color back_color = keyMap_and_profile_to_commit ? UI_MAGENTA : keyMap_to_commit ? UI_RED : profile_to_commit ? UI_BLUE : ui.C4_Exit_onClose.Checked ? Color.Black : UI_GREEN ; //}}} // KEYMAP CHECKBOX STATE {{{ ui.set_C2_KeyMap_commit_Checked(keyMap_to_commit, Globals.CHECKED_PASSIVE); //}}} // COLORS: BORDERS .. LOGO .. MIMINIZE {{{ ui.P_border_U.BackColor = border_color; ui.P_border_R.BackColor = border_color; ui.P_border_D.BackColor = border_color; ui.P_border_L.BackColor = border_color; //}}} // COLORS: SHUTDOWN BUTTON {{{ ui.B_ShutDown.FlatAppearance.BorderColor = border_color; ui.B_ShutDown.BackColor = back_color; ui.B_ShutDown.ForeColor = border_color; ui.L_WRITING.ForeColor = border_color; //}}} // COLORS: CHECKBOXES .. KEYS .. PROFILE .. EXIT {{{ ui.C2_KeyMap_commit.ForeColor = Color.Red; ui.C1_Profile_commit.ForeColor = Color.Blue; ui.C4_Exit_onClose.ForeColor = Color.Black; ui.L_STATUS.BackColor = back_color; ui.L_STATUS.ForeColor = border_color; //}}} // TEXT: KEYS .. PROFILE .. EXIT {{{ string label_keys = (profile.keyProgrammer.KeyMap_changeToCommit != "") ? " " + Globals.SYMBOL_ARROW_R + " Send\nKeys" : Globals.SYMBOL_CHECK + " do not\nSend Keys"; string label_profile = (profile.keyProgrammer.Profile_changeToCommit != "") ? " " + Globals.SYMBOL_ARROW_R + " Save\nProfile" : Globals.SYMBOL_CHECK + " do not\nSave Profile"; string label_exit = ui.C4_Exit_onClose.Checked ? " " + Globals.SYMBOL_ARROW_R + " Exit\non Close" : Globals.SYMBOL_CHECK + " SysTray\non close"; string text = label_keys + "\n\n" + label_profile + "\n\n" + label_exit; string tt = text.Replace("\n", "\r\n"); if (ui.InvokeRequired) { ui.Invoke((MethodInvoker) delegate() { ui.B_ShutDown.Text = text; toolTip.SetToolTip(ui.B_ShutDown, tt); }); } else { ui.B_ShutDown.Text = text; } toolTip.SetToolTip(ui.B_ShutDown, tt); //}}} // OPACITY: COMMIT .. FOCUS {{{ bool pending = (profile.keyProgrammer.KeyMap_changeToCommit != "") || (profile.keyProgrammer.Profile_changeToCommit != "") ; ui.Opacity = ui.L_WRITING.Enabled ? Globals.OPACITY_WRITING : ui.DX1UtilityHasFocus ? (pending ? Globals.OPACITY_PROFILE : Globals.OPACITY_FOCUS) : Globals.OPACITY_UPDATED ; //}}} } //}}} } //}}}
// }}} public void KeyDown(KeyMap CurrentKey, string ExtraData = "") // SPECIAL KEY PRESSED {{{ { KMH_INPUT input = new KMH_INPUT(); switch (CurrentKey.KeyCode) { case 0: // Left Mouse Button //{{{ //Old Code - Mostly Worked //mouse_event(0x02, 0, 0, 0, 0); input.type = INPUT_MOUSE; input.mi.dx = 0; input.mi.dy = 0; input.mi.mouseData = 0; input.mi.dwFlags = (int)MOUSEEVENTF_LEFTDOWN; break; //}}} case 1: // Right Mouse Button //{{{ input.type = INPUT_MOUSE; input.mi.dx = 0; input.mi.dy = 0; input.mi.mouseData = 0; input.mi.dwFlags = (int)MOUSEEVENTF_RIGHTDOWN; break; //}}} case 2: // Middle Mouse Button //{{{ input.type = INPUT_MOUSE; input.mi.dx = 0; input.mi.dy = 0; input.mi.mouseData = 0; input.mi.dwFlags = (int)MOUSEEVENTF_MIDDLEDOWN; break; //}}} case 3: // Mouse Vertical Scroll //{{{ input.type = INPUT_MOUSE; input.mi.dx = 0; input.mi.dy = 0; //Check to see if scrolling Up or down if (CurrentKey.KeyData == "1") { input.mi.mouseData = 100; } else { input.mi.mouseData = -100; } input.mi.dwFlags = (int)MOUSEEVENTF_VWHEEL; break; //}}} case 4: // Mouse Horizontal Scroll //{{{ input.type = INPUT_MOUSE; input.mi.dx = 0; input.mi.dy = 0; //Check to see if scrolling Up or down if (CurrentKey.KeyData == "1") { input.mi.mouseData = 100; } else { input.mi.mouseData = -100; } input.mi.dwFlags = (int)MOUSEEVENTF_HWHEEL; break; //}}} /* case 5: // Media Play/Pause //{{{ * input.ki.wVk = (ushort)MEDIA_PLAY_PAUSE; * input.ki.wScan = 0; * input.ki.dwExtraInfo = IntPtr.Zero; * input.ki.dwFlags = 0; * * break; * //}}} */ default: // Special-Key that can be sent just with the SpecialValue to the Keyboard Input //{{{ log("SpecialKeyPlayer.KeyDown(" + CurrentKey.ToString() + ")"); log("..."); input.type = INPUT_KEYBOARD; input.ki.wVk = _SpecialKeys[CurrentKey.KeyCode].SpecialValue; input.ki.wScan = 0; input.ki.dwExtraInfo = IntPtr.Zero; input.ki.dwFlags = 0; break; //}}} } KMH_INPUT[] inputs = { input }; NativeMethods.SendInput(1, inputs, Marshal.SizeOf(input)); }
} //}}} public static List <KeyMap> LoadProfile(string profileName) //{{{ { if (DX1Utility.Debug) { log("ProfileManager.LoadProfile(" + profileName + "):"); } List <KeyMap> keyMaps = new List <KeyMap>(); // access file {{{ string fileName = Globals.UserProfileFolder + profileName + XML_EXTENSION; if (!System.IO.File.Exists(fileName)) { log("*** FILE NOT FOUND:\n" + fileName); profileName = "Global"; fileName = Globals.UserProfileFolder + "\\Global.xml"; File.Copy("Profiles\\Global.xml", fileName); }//}}} // load file {{{ XmlTextReader reader = null; try { KeyMap keyMap = null; bool readingKeyMap = false; reader = new XmlTextReader(fileName); while (reader.Read()) { // key node line .. <keyMap>..</keyMap> {{{ if (reader.Name == XMLTAG_KEYMAP) { // <keyMap> ..(new key) if (reader.NodeType == XmlNodeType.Element) { keyMap = new KeyMap(); readingKeyMap = true; } // </keyMap> .. (key loaded) else if (reader.NodeType == XmlNodeType.EndElement) { if (keyMap.KeyNum != 0) { keyMaps.Add(keyMap); /*{{{ * log( "ooo\n" +"keyMap=["+ keyMap.ToString() +"]\n" +"keyMap=["+ keyMap.PrettyPrint() +"]\n" +KeyMap_ToXML( keyMap ) * ); * }}}*/ } readingKeyMap = false; } } //}}} // key elements columns .. (num..code..type..name..desc..mac..data) {{{ else if (readingKeyMap) { if (reader.Name == XMLTAG_KEYINDX) { keyMap.KeyNum = (byte )reader.ReadElementContentAs(typeof(byte), null); } else if (reader.Name == XMLTAG_KEYCODE) { keyMap.KeyCode = (byte )reader.ReadElementContentAs(typeof(byte), null); } else if (reader.Name == XMLTAG_KEYTYPE) { keyMap.KeyType = (byte )reader.ReadElementContentAs(typeof(byte), null); } else if (reader.Name == XMLTAG_KEYNAME) { keyMap.KeyName = ((string)reader.ReadElementContentAs(typeof(string), null)).Trim(); } else if (reader.Name == XMLTAG_KEYDESC) { keyMap.KeyDesc = ((string)reader.ReadElementContentAs(typeof(string), null)).Trim(); } else if (reader.Name == XMLTAG_MACNAME) { keyMap.MacName = ((string)reader.ReadElementContentAs(typeof(string), null)).Trim(); } else if (reader.Name == XMLTAG_MAPDATA) { keyMap.KeyData = ((string)reader.ReadElementContentAs(typeof(string), null)).Trim(); } } //}}} } } catch (Exception ex) { log("***ProfileManager.LoadProfileXML(" + profileName + ") Exception:\n" + ex); } finally { if (reader != null) { reader.Close(); } }//}}} if (keyMaps.Count < 1) { log("***Loading " + fileName + " returns an empty KeyMap list"); } else if (DX1Utility.Debug) { log(".. return a KeyMap list of " + keyMaps.Count + " entries"); } return(keyMaps); } //}}}
//[System.Runtime.InteropServices.DllImport("user32.dll")] //public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); public void KeyDown(KeyMap CurrentKey, string ExtraData = "") { //A special key has been pressed //Determine the type of Special Key being pressed //Added for Issue #19 switch (CurrentKey.Type) { case 4: { //4 = Special Key (Mouse, Media, etc) switch (CurrentKey.Action) { case 0: { //Left Mouse Button //Old Code - Mostly Worked //mouse_event(0x02, 0, 0, 0, 0); INPUT input_down = new INPUT(); input_down.type = INPUT_MOUSE; input_down.mi.dx = 0; input_down.mi.dy = 0; input_down.mi.mouseData = 0; input_down.mi.dwFlags = (int)MOUSEEVENTF_LEFTDOWN; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } case 1: { //Right Mouse Button INPUT input_down = new INPUT(); input_down.type = INPUT_MOUSE; input_down.mi.dx = 0; input_down.mi.dy = 0; input_down.mi.mouseData = 0; input_down.mi.dwFlags = (int)MOUSEEVENTF_RIGHTDOWN; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } case 2: { //Middle Mouse Button INPUT input_down = new INPUT(); input_down.type = INPUT_MOUSE; input_down.mi.dx = 0; input_down.mi.dy = 0; input_down.mi.mouseData = 0; input_down.mi.dwFlags = (int)MOUSEEVENTF_MIDDLEDOWN; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } case 3: { //Mouse Vert Scroll INPUT input_down = new INPUT(); input_down.type = INPUT_MOUSE; input_down.mi.dx = 0; input_down.mi.dy = 0; //Check to see if scrolling Up or down if (CurrentKey.CustomData == "1") { input_down.mi.mouseData = 100; } else { input_down.mi.mouseData = -100; } input_down.mi.dwFlags = (int)MOUSEEVENTF_VWHEEL; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } case 4: { //Mouse Horz Scroll INPUT input_down = new INPUT(); input_down.type = INPUT_MOUSE; input_down.mi.dx = 0; input_down.mi.dy = 0; //Check to see if scrolling Up or down if (CurrentKey.CustomData == "1") { input_down.mi.mouseData = 100; } else { input_down.mi.mouseData = -100; } input_down.mi.dwFlags = (int)MOUSEEVENTF_HWHEEL; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } //case 5: // { // //Media Play/Pause // INPUT input_down = new INPUT(); // input_down.ki.wVk = (ushort)MEDIA_PLAY_PAUSE; // input_down.ki.wScan = 0; // input_down.ki.dwExtraInfo = IntPtr.Zero; // input_down.ki.dwFlags = 0; // INPUT[] input = { input_down }; // SendInput(1, input, Marshal.SizeOf(input_down)); // break; // } default: { //Used for any Special Key that can be sent just with the SpecialValue to the Keyboard Input INPUT input_down = new INPUT(); input_down.type = INPUT_KEYBOARD; input_down.ki.wVk = _SpecialKeys[CurrentKey.Action].SpecialValue; input_down.ki.wScan = 0; input_down.ki.dwExtraInfo = IntPtr.Zero; input_down.ki.dwFlags = 0; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); break; } } break; } case 5: { //5 = Toggle Key //Added for Issue #19 DebugLog.Instance.writeLog("Attempting to Toggle key: " + CurrentKey.Action, true); //Check if Key is "0", if so press key (Ignore key in all other states) if (Bags.getValue(CurrentKey.Action) == 0) { INPUT input_down = new INPUT(); input_down.type = INPUT_KEYBOARD; input_down.ki.wVk = CurrentKey.Action; input_down.ki.wScan = 0; input_down.ki.dwExtraInfo = IntPtr.Zero; input_down.ki.dwFlags = 0; INPUT[] input = { input_down }; SendInput(1, input, Marshal.SizeOf(input_down)); //Set Flag to "ON" //Add Key being "pressed" to Dictionary for later removal Bags.AddToggle(CurrentKey.Action, 2); DebugLog.Instance.writeLog(" Key Toggled: " + CurrentKey.Action); } else { DebugLog.Instance.writeLog(" Key NOT Toggled: " + CurrentKey.Action); } break; } default: { break; } } }