//Process the incoming messages from the websocket clients private void ProcessMessage(string Message) { if (Message != "") { string[] split = Message.Split('@'); //If the message is properly formatted (variable@value) if (split.Length == 2) { Log("Received command: " + split[0] + " - " + split[1]); //If the user is not mapping a new command, tries to find a match and send the adequate keypress event if (!isMapping) { if (keyMaps.Exists(d => d.Nome == split[0])) { EventMapping currentMap = keyMaps.Find(d => d.Nome == split[0]); if (currentMap.KeyCode != 0) { if (split[1] == "down") { Keyboard.KeyDown(currentMap.KeyCode); } else if (split[1] == "up") { Keyboard.KeyUp(currentMap.KeyCode); } } } //If the user is mapping a new command, add to the mappings list } else { if (split[1] == "down") { if (!keyMaps.Exists(d => d.Nome == split[0])) { keyMaps.Add(new EventMapping { Nome = split[0], FriendlyKey = "", KeyCode = 0 }); UpdateList(); } } } } } }
private void dgvComandos_KeyDown(object sender, KeyEventArgs e) { //If the user is in mapping mode and clicks the 'Key' column, assign the key to the command if (isMapping) { if (dgvComandos.CurrentCell.ColumnIndex == 1) { string mapName = dgvComandos.CurrentRow.Cells[0].Value.ToString(); if (keyMaps.Exists(d => d.Nome == mapName)) { EventMapping existing = keyMaps.Find(d => d.Nome == mapName); existing.KeyCode = e.KeyCode; existing.FriendlyKey = existing.KeyCode.ToString(); dgvComandos.CurrentRow.Cells[1].Value = existing.FriendlyKey; } } //If the user is not in edit mode, manages the removal of command mappings } else { if (dgvComandos.CurrentRow != null) { if (e.KeyCode == Keys.Delete) { string mapName = dgvComandos.CurrentRow.Cells[0].Value.ToString(); if (MessageBox.Show($"Do you really want to delete '{mapName}'?", "Remove mapping", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { keyMaps.RemoveAll(d => d.Nome == mapName); UpdateList(); } } } } }