diff --git a/HotKeyFileHelper.cs b/HotKeyFileHelper.cs new file mode 100644 index 0000000..f1addbc --- /dev/null +++ b/HotKeyFileHelper.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections; +using WindowsInput.Native; + +namespace OSC_To_keypress_Console +{ + class HotKeyFileReader + { + public string[] readFromFile(string filePath) + { + return System.IO.File.ReadAllLines(filePath); + } + + public HotKeyInfo translalteToHotkeys(string filePath) + { + HotKeyInfo hotkeyInfo = new HotKeyInfo(); + + string[] fileContents = readFromFile(filePath); + int i = 0; + foreach (string line in fileContents) + { + String[] splitLine = line.Split("\t"); + VirtualKeyCode key = (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), splitLine[0], true); + VirtualKeyCode modifier = (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), splitLine[1], true); + string address = splitLine[2]; + + //if has datatypevalue line + if(splitLine.Length == 5) + { + string dataType = splitLine[3]; + string dataTypeValue = splitLine[4]; + hotkeyInfo.addHotKey(i, key, modifier, address, dataType, dataTypeValue); + } + else if(splitLine.Length == 3) + { + hotkeyInfo.addHotKey(i, key, modifier, address); + } + i++; + } + return hotkeyInfo; + } + } + + class HotKeyInfo + { + private List hotkeys; + private List modifiers; + private List addresses; + private List dataTypes; + private List dataTypeValues; + public HotKeyInfo() + { + hotkeys = new List(); + modifiers = new List(); + addresses = new List(); + dataTypes = new List(); + dataTypeValues = new List(); + } + + public void addHotKey(int arrayPosition, VirtualKeyCode hotkey, VirtualKeyCode modifier, string address) + { + hotkeys.Add(hotkey); + modifiers.Add(modifier); + addresses.Add(address); + } + public void addHotKey(int arrayPosition, VirtualKeyCode hotkey, VirtualKeyCode modifier, string address, string dataType, string dataTypeValue) + { + hotkeys.Add(hotkey); + modifiers.Add(modifier); + addresses.Add(address); + dataTypes.Add(dataType); + dataTypeValues.Add(dataTypeValue); + } + + public VirtualKeyCode getHotkey(int position) + { + return hotkeys[position]; + } + public VirtualKeyCode getModifier(int position) + { + return modifiers[position]; + } + + public string getAddress(int position) + { + return addresses[position]; + } + + public string getDataType(int position) + { + return dataTypes[position]; + } + + public string getDataTypeValue(int position) + { + return dataTypeValues[position]; + } + + public int getHotkeyCount() + { + return hotkeys.Count; + } + + } +} diff --git a/InfoForKeys.txt b/InfoForKeys.txt new file mode 100644 index 0000000..098fe39 --- /dev/null +++ b/InfoForKeys.txt @@ -0,0 +1,712 @@ + // + // Summary: + // The list of VirtualKeyCodes (see: http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx) + public enum VirtualKeyCode + { + None = 0, + // + // Summary: + // Left mouse button + LBUTTON = 1, + // + // Summary: + // Right mouse button + RBUTTON = 2, + // + // Summary: + // Control-break processing + CANCEL = 3, + // + // Summary: + // Middle mouse button (three-button mouse) - NOT contiguous with LBUTTON and RBUTTON + MBUTTON = 4, + // + // Summary: + // Windows 2000/XP: X1 mouse button - NOT contiguous with LBUTTON and RBUTTON + XBUTTON1 = 5, + // + // Summary: + // Windows 2000/XP: X2 mouse button - NOT contiguous with LBUTTON and RBUTTON + XBUTTON2 = 6, + // + // Summary: + // BACKSPACE key + BACK = 8, + // + // Summary: + // TAB key + TAB = 9, + // + // Summary: + // CLEAR key + CLEAR = 12, + // + // Summary: + // ENTER key + RETURN = 13, + // + // Summary: + // SHIFT key + SHIFT = 0x10, + // + // Summary: + // CTRL key + CONTROL = 17, + // + // Summary: + // ALT key + MENU = 18, + // + // Summary: + // PAUSE key + PAUSE = 19, + // + // Summary: + // CAPS LOCK key + CAPITAL = 20, + // + // Summary: + // Input Method Editor (IME) Kana mode + KANA = 21, + // + // Summary: + // IME Hanguel mode (maintained for compatibility; use HANGUL) + HANGEUL = 21, + // + // Summary: + // IME Hangul mode + HANGUL = 21, + // + // Summary: + // IME Junja mode + JUNJA = 23, + // + // Summary: + // IME final mode + FINAL = 24, + // + // Summary: + // IME Hanja mode + HANJA = 25, + // + // Summary: + // IME Kanji mode + KANJI = 25, + // + // Summary: + // ESC key + ESCAPE = 27, + // + // Summary: + // IME convert + CONVERT = 28, + // + // Summary: + // IME nonconvert + NONCONVERT = 29, + // + // Summary: + // IME accept + ACCEPT = 30, + // + // Summary: + // IME mode change request + MODECHANGE = 0x1F, + // + // Summary: + // SPACEBAR + SPACE = 0x20, + // + // Summary: + // PAGE UP key + PRIOR = 33, + // + // Summary: + // PAGE DOWN key + NEXT = 34, + // + // Summary: + // END key + END = 35, + // + // Summary: + // HOME key + HOME = 36, + // + // Summary: + // LEFT ARROW key + LEFT = 37, + // + // Summary: + // UP ARROW key + UP = 38, + // + // Summary: + // RIGHT ARROW key + RIGHT = 39, + // + // Summary: + // DOWN ARROW key + DOWN = 40, + // + // Summary: + // SELECT key + SELECT = 41, + // + // Summary: + // PRINT key + PRINT = 42, + // + // Summary: + // EXECUTE key + EXECUTE = 43, + // + // Summary: + // PRINT SCREEN key + SNAPSHOT = 44, + // + // Summary: + // INS key + INSERT = 45, + // + // Summary: + // DEL key + DELETE = 46, + // + // Summary: + // HELP key + HELP = 47, + // + // Summary: + // 0 key + VK_0 = 48, + // + // Summary: + // 1 key + VK_1 = 49, + // + // Summary: + // 2 key + VK_2 = 50, + // + // Summary: + // 3 key + VK_3 = 51, + // + // Summary: + // 4 key + VK_4 = 52, + // + // Summary: + // 5 key + VK_5 = 53, + // + // Summary: + // 6 key + VK_6 = 54, + // + // Summary: + // 7 key + VK_7 = 55, + // + // Summary: + // 8 key + VK_8 = 56, + // + // Summary: + // 9 key + VK_9 = 57, + // + // Summary: + // A key + VK_A = 65, + // + // Summary: + // B key + VK_B = 66, + // + // Summary: + // C key + VK_C = 67, + // + // Summary: + // D key + VK_D = 68, + // + // Summary: + // E key + VK_E = 69, + // + // Summary: + // F key + VK_F = 70, + // + // Summary: + // G key + VK_G = 71, + // + // Summary: + // H key + VK_H = 72, + // + // Summary: + // I key + VK_I = 73, + // + // Summary: + // J key + VK_J = 74, + // + // Summary: + // K key + VK_K = 75, + // + // Summary: + // L key + VK_L = 76, + // + // Summary: + // M key + VK_M = 77, + // + // Summary: + // N key + VK_N = 78, + // + // Summary: + // O key + VK_O = 79, + // + // Summary: + // P key + VK_P = 80, + // + // Summary: + // Q key + VK_Q = 81, + // + // Summary: + // R key + VK_R = 82, + // + // Summary: + // S key + VK_S = 83, + // + // Summary: + // T key + VK_T = 84, + // + // Summary: + // U key + VK_U = 85, + // + // Summary: + // V key + VK_V = 86, + // + // Summary: + // W key + VK_W = 87, + // + // Summary: + // X key + VK_X = 88, + // + // Summary: + // Y key + VK_Y = 89, + // + // Summary: + // Z key + VK_Z = 90, + // + // Summary: + // Left Windows key (Microsoft Natural keyboard) + LWIN = 91, + // + // Summary: + // Right Windows key (Natural keyboard) + RWIN = 92, + // + // Summary: + // Applications key (Natural keyboard) + APPS = 93, + // + // Summary: + // Computer Sleep key + SLEEP = 95, + // + // Summary: + // Numeric keypad 0 key + NUMPAD0 = 96, + // + // Summary: + // Numeric keypad 1 key + NUMPAD1 = 97, + // + // Summary: + // Numeric keypad 2 key + NUMPAD2 = 98, + // + // Summary: + // Numeric keypad 3 key + NUMPAD3 = 99, + // + // Summary: + // Numeric keypad 4 key + NUMPAD4 = 100, + // + // Summary: + // Numeric keypad 5 key + NUMPAD5 = 101, + // + // Summary: + // Numeric keypad 6 key + NUMPAD6 = 102, + // + // Summary: + // Numeric keypad 7 key + NUMPAD7 = 103, + // + // Summary: + // Numeric keypad 8 key + NUMPAD8 = 104, + // + // Summary: + // Numeric keypad 9 key + NUMPAD9 = 105, + // + // Summary: + // Multiply key + MULTIPLY = 106, + // + // Summary: + // Add key + ADD = 107, + // + // Summary: + // Separator key + SEPARATOR = 108, + // + // Summary: + // Subtract key + SUBTRACT = 109, + // + // Summary: + // Decimal key + DECIMAL = 110, + // + // Summary: + // Divide key + DIVIDE = 111, + // + // Summary: + // F1 key + F1 = 112, + // + // Summary: + // F2 key + F2 = 113, + // + // Summary: + // F3 key + F3 = 114, + // + // Summary: + // F4 key + F4 = 115, + // + // Summary: + // F5 key + F5 = 116, + // + // Summary: + // F6 key + F6 = 117, + // + // Summary: + // F7 key + F7 = 118, + // + // Summary: + // F8 key + F8 = 119, + // + // Summary: + // F9 key + F9 = 120, + // + // Summary: + // F10 key + F10 = 121, + // + // Summary: + // F11 key + F11 = 122, + // + // Summary: + // F12 key + F12 = 123, + // + // Summary: + // F13 key + F13 = 124, + // + // Summary: + // F14 key + F14 = 125, + // + // Summary: + // F15 key + F15 = 126, + // + // Summary: + // F16 key + F16 = 0x7F, + // + // Summary: + // F17 key + F17 = 0x80, + // + // Summary: + // F18 key + F18 = 129, + // + // Summary: + // F19 key + F19 = 130, + // + // Summary: + // F20 key + F20 = 131, + // + // Summary: + // F21 key + F21 = 132, + // + // Summary: + // F22 key + F22 = 133, + // + // Summary: + // F23 key + F23 = 134, + // + // Summary: + // F24 key + F24 = 135, + // + // Summary: + // NUM LOCK key + NUMLOCK = 144, + // + // Summary: + // SCROLL LOCK key + SCROLL = 145, + // + // Summary: + // Left SHIFT key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + LSHIFT = 160, + // + // Summary: + // Right SHIFT key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + RSHIFT = 161, + // + // Summary: + // Left CONTROL key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + LCONTROL = 162, + // + // Summary: + // Right CONTROL key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + RCONTROL = 163, + // + // Summary: + // Left MENU key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + LMENU = 164, + // + // Summary: + // Right MENU key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + RMENU = 165, + // + // Summary: + // Windows 2000/XP: Browser Back key + BROWSER_BACK = 166, + // + // Summary: + // Windows 2000/XP: Browser Forward key + BROWSER_FORWARD = 167, + // + // Summary: + // Windows 2000/XP: Browser Refresh key + BROWSER_REFRESH = 168, + // + // Summary: + // Windows 2000/XP: Browser Stop key + BROWSER_STOP = 169, + // + // Summary: + // Windows 2000/XP: Browser Search key + BROWSER_SEARCH = 170, + // + // Summary: + // Windows 2000/XP: Browser Favorites key + BROWSER_FAVORITES = 171, + // + // Summary: + // Windows 2000/XP: Browser Start and Home key + BROWSER_HOME = 172, + // + // Summary: + // Windows 2000/XP: Volume Mute key + VOLUME_MUTE = 173, + // + // Summary: + // Windows 2000/XP: Volume Down key + VOLUME_DOWN = 174, + // + // Summary: + // Windows 2000/XP: Volume Up key + VOLUME_UP = 175, + // + // Summary: + // Windows 2000/XP: Next Track key + MEDIA_NEXT_TRACK = 176, + // + // Summary: + // Windows 2000/XP: Previous Track key + MEDIA_PREV_TRACK = 177, + // + // Summary: + // Windows 2000/XP: Stop Media key + MEDIA_STOP = 178, + // + // Summary: + // Windows 2000/XP: Play/Pause Media key + MEDIA_PLAY_PAUSE = 179, + // + // Summary: + // Windows 2000/XP: Start Mail key + LAUNCH_MAIL = 180, + // + // Summary: + // Windows 2000/XP: Select Media key + LAUNCH_MEDIA_SELECT = 181, + // + // Summary: + // Windows 2000/XP: Start Application 1 key + LAUNCH_APP1 = 182, + // + // Summary: + // Windows 2000/XP: Start Application 2 key + LAUNCH_APP2 = 183, + // + // Summary: + // Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: + // For the US standard keyboard, the ';:' key + OEM_1 = 186, + // + // Summary: + // Windows 2000/XP: For any country/region, the '+' key + OEM_PLUS = 187, + // + // Summary: + // Windows 2000/XP: For any country/region, the ',' key + OEM_COMMA = 188, + // + // Summary: + // Windows 2000/XP: For any country/region, the '-' key + OEM_MINUS = 189, + // + // Summary: + // Windows 2000/XP: For any country/region, the '.' key + OEM_PERIOD = 190, + // + // Summary: + // Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: + // For the US standard keyboard, the '/?' key + OEM_2 = 191, + // + // Summary: + // Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: + // For the US standard keyboard, the '`~' key + OEM_3 = 192, + // + // Summary: + // Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: + // For the US standard keyboard, the '[{' key + OEM_4 = 219, + // + // Summary: + // Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: + // For the US standard keyboard, the '\|' key + OEM_5 = 220, + // + // Summary: + // Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: + // For the US standard keyboard, the ']}' key + OEM_6 = 221, + // + // Summary: + // Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: + // For the US standard keyboard, the 'single-quote/double-quote' key + OEM_7 = 222, + // + // Summary: + // Used for miscellaneous characters; it can vary by keyboard. + OEM_8 = 223, + // + // Summary: + // Windows 2000/XP: Either the angle bracket key or the backslash key on the RT + // 102-key keyboard + OEM_102 = 226, + // + // Summary: + // Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key + PROCESSKEY = 229, + // + // Summary: + // Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. + // The PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard + // input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, + // and WM_KEYUP + PACKET = 231, + // + // Summary: + // Attn key + ATTN = 246, + // + // Summary: + // CrSel key + CRSEL = 247, + // + // Summary: + // ExSel key + EXSEL = 248, + // + // Summary: + // Erase EOF key + EREOF = 249, + // + // Summary: + // Play key + PLAY = 250, + // + // Summary: + // Zoom key + ZOOM = 251, + // + // Summary: + // Reserved + NONAME = 252, + // + // Summary: + // PA1 key + PA1 = 253, + // + // Summary: + // Clear key + OEM_CLEAR = 254 + } +} + diff --git a/OSC_To_keypress_Console.csproj b/OSC_To_keypress_Console.csproj new file mode 100644 index 0000000..39e9bfd --- /dev/null +++ b/OSC_To_keypress_Console.csproj @@ -0,0 +1,24 @@ + + + + Exe + net6.0-windows + true + enable + enable + + + + + + sxzd + + + + + + SharpOSC.dll + + + + diff --git a/OSC_To_keypress_Console.sln b/OSC_To_keypress_Console.sln new file mode 100644 index 0000000..b1f06fd --- /dev/null +++ b/OSC_To_keypress_Console.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32210.238 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSC_To_keypress_Console", "OSC_To_keypress_Console.csproj", "{F0503D34-628E-48FC-9AE1-203C65AD0581}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F0503D34-628E-48FC-9AE1-203C65AD0581}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F0503D34-628E-48FC-9AE1-203C65AD0581}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F0503D34-628E-48FC-9AE1-203C65AD0581}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F0503D34-628E-48FC-9AE1-203C65AD0581}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CD0716F5-8100-4869-B8E2-1AF7B1118BD7} + EndGlobalSection +EndGlobal diff --git a/OscToKeypress.cs b/OscToKeypress.cs new file mode 100644 index 0000000..d1e6807 --- /dev/null +++ b/OscToKeypress.cs @@ -0,0 +1,240 @@ +extern alias sxzd; + +using sxzd::Rug.Osc; +using WindowsInput.Native; +using System.Net; +using System.Runtime.InteropServices; +using System.Windows.Input; +using System.Windows.Forms; + +namespace OSC_To_keypress_Console +{ + class OscToKeypress + { + static OscReceiver receiver; + static OscSender sender; + static Thread recieveThread; + static Thread sendThread; + + private static IntPtr _hookID = IntPtr.Zero; + [DllImport("user32.dll")] + public static extern bool RegisterHotKey(IntPtr hWnd, IntPtr hHotKey); + [DllImport("user32.dll")] + public static extern bool UnregisterHotKey(IntPtr hWnd, int id); + + + static void Main(string[] args) + { + + + // This is the port we are going to listen on + int port = 9001; + int sendPort = 9000; + IPAddress address = IPAddress.Parse("127.0.0.1"); + + // Create the receiver + Console.WriteLine("Receiving Port: " + port); + receiver = new OscReceiver(port); + + Console.WriteLine("Sending Port: " + sendPort); + sender = new OscSender(address,port,sendPort); + + + // Create a thread to do the listening + recieveThread = new Thread(new ThreadStart(ListenLoop)); + sendThread = new Thread(new ThreadStart(SenderListenLoop)); + + // Connect the receiver + receiver.Connect(); + + sender.Connect(); + + // Start the listen thread + recieveThread.Start(); + + // Start the send thread + sendThread.Start(); + + // wait for a key press to exit + Console.Title = "OSC To Keybind"; + Console.WriteLine("Please reference the Readme for info on setting Parameters and associated Keybinds"); + //Console.WriteLine("Press any key to exit"); + //Console.ReadKey(true); + + // close the Reciver + //receiver.Close(); + + // Wait for the listen thread to exit + //recieveThread.Join(); + //sendThread.Join(); + } + + static void SenderListenLoop() + { + HotKeyFileReader senderFileReader = new HotKeyFileReader(); + HotKeyInfo senderHotkeys = senderFileReader.translalteToHotkeys("SenderHotkeys.txt"); + KeybindToOSC[] senderKeybinds = new KeybindToOSC[senderHotkeys.getHotkeyCount()]; + if (senderHotkeys.getHotkeyCount() == 0) + { + Console.WriteLine("--"); + Console.Write("SenderHotkeys.txt contains no defined hotkeys."); + } + //Generate listeners for keypresses + for (int i = 0; i < senderHotkeys.getHotkeyCount(); i++) + { + senderKeybinds[i] = new KeybindToOSC(senderHotkeys.getHotkey(i), senderHotkeys.getModifier(i), senderHotkeys.getAddress(i), senderHotkeys.getDataType(i), senderHotkeys.getDataTypeValue(i)); + } + + try + { + while (true) + { + for (int i = 0; i < senderHotkeys.getHotkeyCount(); i++) + { + //check each listener to see if its keybind has been pressed. + if(senderKeybinds[i].listenForKeybind()) + { + //Connect the sender + sender.Send(senderKeybinds[i].generateOSCMessage()); + sender.WaitForAllMessagesToComplete(); + } + } + } + } + catch (Exception ex) + { + // if the socket was connected when this happens + // then tell the user + if (sender.State == OscSocketState.Connected) + { + Console.WriteLine("Exception in sender listen loop"); + Console.WriteLine(ex.Message); + } + } + } + + static void ListenLoop() + { + HotKeyFileReader receiverFileReader = new HotKeyFileReader(); + HotKeyInfo receiverHotkeys = receiverFileReader.translalteToHotkeys("ReceiverHotkeys.txt"); + OSCToKeybind[] receiverKeybinds = new OSCToKeybind[receiverHotkeys.getHotkeyCount()]; + if(receiverHotkeys.getHotkeyCount() == 0) + { + Console.WriteLine("--"); + Console.Write("ReceiverHotkeys.txt contains no defined hotkeys."); + } + //Generate listeners for ocs packets. + for (int i = 0; i < receiverHotkeys.getHotkeyCount(); i++) + { + receiverKeybinds[i] = new OSCToKeybind(receiverHotkeys.getHotkey(i), receiverHotkeys.getModifier(i), receiverHotkeys.getAddress(i)); + } + + try + { + while (receiver.State != OscSocketState.Closed) + { + // if we are in a state to recieve + if (receiver.State == OscSocketState.Connected) + { + // get the next message + // this will block until one arrives or the socket is closed + OscPacket packet = receiver.Receive(); + for (int i = 0; i < receiverHotkeys.getHotkeyCount(); i++) + { + //let each receiver see the package and determine if it is one it handles. + receiverKeybinds[i].receiveOSCRequest(packet); + } + } + } + } + catch (Exception ex) + { + // if the socket was connected when this happens + // then tell the user + if (receiver.State == OscSocketState.Connected) + { + Console.WriteLine("Exception in listen loop"); + Console.WriteLine(ex.Message); + } + } + } + + + } + class OSCToKeybind{ + VirtualKeyCode key; + VirtualKeyCode keyMod; + String address; + + public OSCToKeybind(VirtualKeyCode key, VirtualKeyCode keyMod, String address) + { + this.key = key; + this.keyMod = keyMod; + this.address = address; + } + + public void receiveOSCRequest(OscPacket packet) + { + if (packet.ToString().Split()[0] == address+",") + { + var simulator = new WindowsInput.InputSimulator(); + //Run a keystroke command using given modifier. + simulator.Keyboard.ModifiedKeyStroke(keyMod, key); + Console.WriteLine("--"); + Console.WriteLine("OSC Packet Received:" + packet.ToString()); + Console.WriteLine("Running associated Hotkey: "+key+" + "+keyMod); + } + } + } + + + class KeybindToOSC + { + VirtualKeyCode key; + VirtualKeyCode keyMod; + String address; + String dataType; + String dataTypeValue; + public KeybindToOSC(VirtualKeyCode key, VirtualKeyCode keyMod, String address, String dataType, String dataTypeValue) + { + this.key = key; + this.keyMod = keyMod; + this.address = address; + this.dataType = dataType; + this.dataTypeValue = dataTypeValue; + } + + public bool listenForKeybind() + { + var simulator = new WindowsInput.InputSimulator(); + if(simulator.InputDeviceState.IsKeyDown(key) && simulator.InputDeviceState.IsKeyDown(keyMod)){ + Console.WriteLine("--"); + Console.WriteLine("Keybind detected: " + key + " + " + keyMod); + return true; + } + return false; + } + + public OscMessage generateOSCMessage() + { + OscMessage message = null; + switch (dataType) + { + case "int": + message = new OscMessage(address, int.Parse(dataTypeValue)); + break; + case "float": + message = new OscMessage(address, float.Parse(dataTypeValue)); + break; + case "bool": + message = new OscMessage(address, bool.Parse(dataTypeValue)); + break; + } + Console.WriteLine("Sending associated message: " + message.ToString()); + return message; + } + } + + + +} \ No newline at end of file diff --git a/Readme.txt b/Readme.txt new file mode 100644 index 0000000..da884a2 --- /dev/null +++ b/Readme.txt @@ -0,0 +1,54 @@ +This is a simple console based application that allows you to take an OSC output and translate it to a keypress, +or take a keypress and translate it to an OSC input. + +To send a key combination from a OSCMessage: +Have a parameter on your avatar that matches one of the lines in 'ReceiverHotkeys.txt', and a keybind added in the program you want to activate that matches the key combination. + + +To send a OSCMessage from a key combination +A parameter on your model that you want to trigger from a keybind and an associated line in the 'SenderHotkeys.txt' file. + + +Then you just run the program OSC_To_keypress_Console.exe, and activate OSC from the radial menu in VrChat. +Once it is running toggling any parameter will send an OSCMessage to activate the associated keybind, +and pressing any defined keybind will send the associated values to the OSCAddress. + + +The folder the OSC_To_keypress_Console.exe is in must inclued a file named 'ReceiverHotkeys.txt', and 'SenderHotkeys.txt'. +These files contain the hotkeys binds. + +The 'ReceiverHotkeys.txt', and 'SenderHotkeys.txt' files use windows forms Keys names https://docs.microsoft.com/en-us/uwp/api/windows.system.virtualkey?view=winrt-22000. +Reference the included InfoForKeys.txt for specific key names. +Some oddities of note: +MENU is the keyname for ALT. + +---------------- +'ReceiverHotkeys.txt' defines OSC Outputs that should trigger system key presses. +The file can be empty if you do not want any OSC Outputs to trigger system key presses. + +Each line of the file must be in the format: + +Key_Name{tab}Key_Name{tab}OSC_Address + +example line: +NUMPAD1 LCONTROL /avatar/parameters/keybind1 + + +If the given OSC_Address is recieved the associated key combination will be triggered. + +---------------- +'SenderHotkeys.txt' defines system key presses that should trigger OSC Inputs. +The file can be empty if you do not want any key presses to trigger OSC inputs. + +Each line of the file must be in the format: + +Key_Name{tab}Key_Name{tab}OSC_Address{tab}data_type{tab}data_type_value + +example lines: +VK_A MENU /avatar/parameters/keypress1 bool true +VK_B MENU /avatar/parameters/keypress2 int 1 +VK_C MENU /avatar/parameters/keypress3 float 1.2 + +The data_type names are case sensitive. + +If the given key combination is triggered the associated dataType and value will be sent to the given OSC_Address. \ No newline at end of file diff --git a/ReceiverHotkeys.txt b/ReceiverHotkeys.txt new file mode 100644 index 0000000..f8b9578 --- /dev/null +++ b/ReceiverHotkeys.txt @@ -0,0 +1,5 @@ +NUMPAD1 LCONTROL /avatar/parameters/keybind1 +NUMPAD2 LCONTROL /avatar/parameters/keybind2 +NUMPAD3 LCONTROL /avatar/parameters/keybind3 +NUMPAD4 LCONTROL /avatar/parameters/keybind4 +NUMPAD5 LCONTROL /avatar/parameters/keybind5 \ No newline at end of file diff --git a/SenderHotkeys.txt b/SenderHotkeys.txt new file mode 100644 index 0000000..fec8b1f --- /dev/null +++ b/SenderHotkeys.txt @@ -0,0 +1,6 @@ +VK_A MENU /avatar/parameters/keypress1 bool true +VK_B MENU /avatar/parameters/keypress2 int 1 +VK_C MENU /avatar/parameters/keypress3 float 1.2 +VK_A CONTROL /avatar/parameters/keypress1 bool false +VK_B CONTROL /avatar/parameters/keypress2 int 0 +VK_C CONTROL /avatar/parameters/keypress3 float 0 \ No newline at end of file