Esempio n. 1
0
        public static void Start(HookCallback keyboardCallback, HookCallback mouseCallback)
        {
            OSHelper.Os os = OSHelper.GetOsVersion();
            if (os.System != OSHelper.Platform.Windows)
            {
                throw new InvalidOperatingSystemException("Windowhook can only be run on windows machines!");
            }

            if (Running)
            {
                throw new InvalidCastException("Windowhook already running");
            }

            ISLogger.Write("Starting Windowhook on " + os);

            KeyboardProcPtr = SetKeyboardHook(keyboardCallback);
            if (KeyboardProcPtr == IntPtr.Zero)
            {
                throw new Win32Exception("An error occurred while installing keyboard hook. Win32 error code " + Marshal.GetLastWin32Error());
            }
            else
            {
                ISLogger.Write("Installed keyboard hook");
            }

            MouseProcPtr = SetMouseHook(mouseCallback);
            if (MouseProcPtr == IntPtr.Zero)
            {
                throw new Win32Exception("An error occurred while installing mouse hook. Win32 error code " + Marshal.GetLastWin32Error());
            }
            else
            {
                ISLogger.Write("Installed Mouse hook");
            }

            Running = true;
        }
Esempio n. 2
0
        public void Start(int port)
        {
            if (Running)
            {
                throw new InvalidOperationException("Server already running");
            }

            try
            {
                Process.GetCurrentProcess().PriorityClass = ServerBasePriority;
            }catch (Exception ex)
            {
                ISLogger.Write("Cannot set process priority to {0}: {1}", ServerBasePriority, ex.Message);
            }


            ConnectedClient.LocalHost = new ConnectedClient(true);
            ISLogger.Write("Starting server...");
            ServerPort = port;
            clientMan  = new ClientManager(ServerDefaultMaxClients);
            clientMan.AddClient(ConnectedClient.LocalHost);
            tcpListener = new ClientListener();
            tcpListener.ClientConnected += TcpListener_ClientConnected;


            tcpListener.Start(port);


            SetConsoleText("Current client: localhost");

            //We need to determine which OS is being used
            OSHelper.Os os = OSHelper.GetOsVersion();

            switch (os.System)
            {
            case OSHelper.Platform.Windows:
            {
                inputMan    = new WindowsInputManager();
                curMonitor  = new WindowsCursorMonitor();
                outManager  = new WindowsOutputManager();
                procMonitor = new WindowsProcessMonitor();
                break;
            }

            default:
                throw new NotImplementedException();
            }
            inputMan.Start();

            curMonitor.Start();
            curMonitor.EdgeHit += LocalHost_EdgeHit;

            procMonitor.StartMonitoring();
            procMonitor.ProcessEnteredFullscreen += ProcMonitor_ProcessEnteredFullscreen;
            procMonitor.ProcessExitedFullscreen  += ProcMonitor_ProcessExitedFullscreen;
            Running = true;

            inputMan.InputReceived         += InputMan_InputReceived;
            inputMan.ClientHotkeyPressed   += InputMan_ClientHotkeyPressed;
            inputMan.FunctionHotkeyPressed += InputMan_FunctionHotkeyPressed;
            inputMan.ClipboardTextCopied   += InputMan_ClipboardTextCopied;

            LoadHotkeySettings();
        }