Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using MouseKeyboardActivityMonitor;
- using System.Windows.Forms;
- using System.Net.Sockets;
- using System.Threading;
- using System.Net;
- using System.IO;
- using WindowsInput;
- using Interceptor;
- namespace UniversalMacro {
- public class UdpInputDevice : GenericInputDevice {
- string _ipAddress;
- public string IpAddress {
- get {
- return _ipAddress;
- }
- set {
- _ipAddress = value;
- }
- }
- public UdpInputDevice(string ipAddress, string name) {
- _ipAddress = ipAddress;
- Name = name;
- }
- public override void CreateDeviceThread(KeyboardHookListener keyboardListener, Button learnButton, Button macroButton) {
- Thread thread = new Thread(new ThreadStart(delegate {
- Input input = new Input();
- input.Load();
- input.KeyboardFilterMode = KeyboardFilterMode.All;
- IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 18000);
- UdpClient client = new UdpClient(ipEndPoint);
- while (true) {
- using (MemoryStream inputStream = new MemoryStream(client.Receive(ref ipEndPoint))) {
- using (StreamReader reader = new StreamReader(inputStream)) {
- string ipAddress = reader.ReadLine();
- if (ipAddress == _ipAddress) {
- string buttonAffected = reader.ReadLine();
- string buttonAction = reader.ReadLine();
- int keyIndex = 0;
- if (!LearnKey && !LearnMacro) {
- for (int i = 0; i < KeyBindings.Count; i++) {
- if ((KeyBindings[i].Key as string) == buttonAffected) {
- keyIndex = i;
- CurrentKey = KeyBindings[i].Value;
- break;
- } else {
- CurrentKey = null;
- }
- }
- switch (buttonAction) {
- case "[down]":
- InputSimulator.SimulateKeyDown(TranslateToVirtualKeyCode(CurrentKey));
- input.SendKey(TranslateToInterceptorKey(CurrentKey), Interceptor.KeyState.Down);
- break;
- case "[up]":
- InputSimulator.SimulateKeyUp(TranslateToVirtualKeyCode(CurrentKey));
- input.SendKey(TranslateToInterceptorKey(CurrentKey), Interceptor.KeyState.Up);
- break;
- }
- } else if (LearnedButton == null && LearnKey) {
- learnButton.Invoke(new MethodInvoker(delegate {
- LearnedButton = buttonAffected;
- learnButton.Text = "Press Keyboard Button";
- }));
- } else if (LearnMacro) {
- LearnMacro = false;
- NamingDialogue dialogue = new NamingDialogue();
- if (dialogue.ShowDialog() == DialogResult.OK) {
- KeyBindings.Add(new KeyValuePair<object, string>(buttonAffected, dialogue.StringEntered + ".macro"));
- macroButton.Invoke(new MethodInvoker(delegate {
- macroButton.Text = "Bind To Macro";
- macroButton.Enabled = true;
- macroButton.Parent.Enabled = true;
- }));
- }
- }
- }
- }
- }
- }
- }));
- thread.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment