Exemplo n.º 1
0
 public MainForm()
 {
     InitializeComponent();
     Hotkey.RegisterHotKey(Handle, 100, KeyModifiers.Shift,
                           Keys.D);
     _imitateItem = new ImitateItem();
     Drive.Initial();
 }
Exemplo n.º 2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (!File.Exists("imitateItem.json"))
            {
                Initial();
            }
            else
            {
                try
                {
                    _imitateItem = JsonConvert.DeserializeObject <ImitateItem>(File.ReadAllText("imitateItem.json"));

                    foreach (var mouseImitateItem in from mouseImitate in _imitateItem.MouseImitateItems.Values
                             let count = pnlMouse.Controls.Count
                                         select new MouseImitateItem(count * 220, mouseImitate.Index, mouseImitate.Name,
                                                                     mouseImitate.Operate, mouseImitate.PositionX, mouseImitate.PositionY, mouseImitate.Interval,
                                                                     mouseImitate.Hotkey, RemoveMouseEventHandler,
                                                                     SetUpMouseSwitchHotkeyEventHandler))
                    {
                        Hotkey.RegisterHotKey(Handle, mouseImitateItem.HotkeyId, KeyModifiers.Alt,
                                              mouseImitateItem.Hotkey);

                        pnlMouse.Controls.Add(mouseImitateItem.GrpMouseItem);

                        _imitateItem.MouseImitateItems.Add(mouseImitateItem.Index, mouseImitateItem);
                    }

                    foreach (var keyboardImitateItem in from keyboardImitate in _imitateItem.KeyboardImitateItems.Values
                             let count = pnlKeyboard.Controls.Count
                                         select new KeyboardImitateItem(count * 220, keyboardImitate.Index, keyboardImitate.Name,
                                                                        keyboardImitate.Operate, keyboardImitate.Interval, keyboardImitate.Hotkey,
                                                                        RemoveKeyboardEventHandler,
                                                                        SetUpKeyBoardSwitchHotkeyEventHandler))
                    {
                        Hotkey.RegisterHotKey(Handle, keyboardImitateItem.HotkeyId, KeyModifiers.Ctrl,
                                              keyboardImitateItem.Hotkey);

                        pnlKeyboard.Controls.Add(keyboardImitateItem.GrpKeyboardItem);

                        _imitateItem.KeyboardImitateItems.Add(keyboardImitateItem.Index, keyboardImitateItem);
                    }
                }
                catch (Exception)
                {
                    Initial();
                }
            }
        }