Esempio n. 1
0
        public Form1()
        {
            InitializeComponent();
            hkRecorder      = new HotKeyRecorder();
            hkListener      = new HotKeyListener();
            kbHook          = new ClientKeyboardHook();
            kbHook.KeyDown += hkListener.KeyDownListen;
            kbHook.KeyUp   += hkListener.KeyUpListen;

            //hkRecorder.HotKeyRecordedEvent += (HotKey hk) =>
            //{
            //    hk.HotKeyHappened += hk_HotKeyEvent;
            //    hkListener.Add(hk);
            //    label1.Text += "HotKeyRegistered: " + hk.ToString() + "\n";
            //};
            hkRecorder.HotKeyRecorded += (object sender, HotKeyRecordedArgs e) =>
            {
                e.hotKey.HotKeyHappened += hk_HotKeyEvent;
                if (hkListener.Add(e.hotKey))
                {
                    label1.Text += "HotKeyRegistered: " + e.hotKey.ToString() + "\n";
                }
                else
                {
                    label1.Text += e.hotKey.ToString() + " can't be registered\n";
                }
            };

            hkRecorder.KeyRecorded += (object sender, HotKeyRecordedArgs e) =>
            {
                label2.Text = "Recording: " + e.hotKey.ToString();
            };
        }
Esempio n. 2
0
        private HotKeyListener hkListener       = new HotKeyListener();     // ascolta se viene premuto una combinazione di tasti e ne esegue l'handler

        public FormClient()
        {
            InitializeComponent();

            HotKey hk_exit = new HotKey(Keys.LControlKey, Keys.F12);

            // Evento eseguito quando viene premuto l'hotkey: smetti di catturare e inviare gli eventi (flag active da true a false)
            hk_exit.HotKeyHappened += (object sender, EventArgs e) =>
            {
                //simulare keyup qua
                hk_exit.SimulateKeysUp();

                keyboardHook.Stop();
                mouseHook.Stop();
                //Thread.Sleep(timer1.Interval);
                timer1.Stop();

                if (events.Count > 0)
                {
                    EventsBuffer.AddEvents(events);
                    cs.SendEventsList(EventsBuffer.ConsumeEvents());
                    events = new List <MacroEvent>();
                }

                active = false;
                EventsBuffer.Close();
            };
            hkListener.Add(hk_exit);

            //foreach(server s in serverfarm)
            // s.hotkey.hotkeyhappened += clientsocket.connecttoserver(s.ip,s.port);

            mouseHook.MouseMove  += new MouseEventHandler(mouseHook_MouseMove);
            mouseHook.MouseDown  += new MouseEventHandler(mouseHook_MouseDown);
            mouseHook.MouseUp    += new MouseEventHandler(mouseHook_MouseUp);
            mouseHook.MouseWheel += new MouseEventHandler(mouseHook_MouseWheel);

            keyboardHook.KeyDown += new KeyEventHandler(keyboardHook_KeyDown);
            keyboardHook.KeyUp   += new KeyEventHandler(keyboardHook_KeyUp);
            // Handlers di HotKeyListener vengono eseguiti dopo che gli eventi vengono aggiunti alla lista da inviare
            keyboardHook.KeyDown += hkListener.KeyDownListen;
            keyboardHook.KeyUp   += hkListener.KeyUpListen;


            // Evento: ClientSocket si collega al server (connected da false a true)
            cs.Connected += (object sender, EventArgs e) =>
            {
                connected = true;
                btnAttiva.Invoke(new MethodInvoker(() => { this.btnAttiva.Enabled = true; }));
                btnConnetti.Invoke(new MethodInvoker(() => { this.btnConnetti.Text = "Disconnetti"; }));
            };

            // Evento: ClientSocker non è più collegato al server (connected da true a false)
            cs.Disconnected += (object sender, EventArgs e) =>
            {
                connected = false;
                btnAttiva.Invoke(new MethodInvoker(() => { this.btnAttiva.Enabled = false; }));
                btnConnetti.Invoke(new MethodInvoker(() => { this.btnConnetti.Text = "Connetti"; }));

                // se il server si disconnette mentre il client è attivo
                if (active)
                {
                    keyboardHook.Stop();
                    mouseHook.Stop();
                    timer1.Stop();
                    active = false;
                }
                //EventsBuffer.Close();
            };


            loadServerFarm();

            foreach (Server s in Server_farm.server_list.Values)
            {
                listView1.Items.Add(s.Name);
            }

            if (listView1.Items.Count > 0)
            {
                showServerDetails(Server_farm.server_list[listView1.Items[0].Text]);
                listView1.Items[0].Selected = true;
            }

            listView1.Columns[0].Width = listView1.Width - 4;
        }