public ShortCutModel GetShortCutData() { string jsonStr = File.ReadAllText(JsonPath); ShortCutModel scm = JsonConvert.DeserializeObject <ShortCutModel>(jsonStr); return(scm); }
protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == (int)0x312) { IntPtr msgParam = m.WParam; ShortCutModel scmData = (new ShortCutManager()).GetShortCutData(); List <ShortCutItem> listSci = scmData.ShortCutList.ToList(); if (listSci.Exists(s => (IntPtr)s.id == msgParam)) { ShortCutItem sci = listSci.First(s => (IntPtr)s.id == msgParam); //MessageBox.Show($"{sci.cmd}, {sci.parameters}"); try { Process.Start(sci.cmd, sci.parameters); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "프로그램을 실행하지 못했습니다."); } } // if (m.WParam == (IntPtr) 0x0) // { // Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"); // } // else if (m.WParam == (IntPtr) 0x1) // { // Process.Start("explorer", @"d:\Downloads"); // } } }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { ShortCutModel scmData = (new ShortCutManager()).GetShortCutData(); foreach (ShortCutItem sci in scmData.ShortCutList) { UnregisterHotKey((int)WinHandleToNum, sci.id); } }
private void Form1_Load(object sender, EventArgs e) { this.Visible = false; this.ShowIcon = true; ShortCutModel scmData = (new ShortCutManager()).GetShortCutData(); foreach (ShortCutItem sci in scmData.ShortCutList) { Tuple <int, int, int> tplMods = Tuple.Create(0, 0, 0); int modKey1 = ModKeyDefines.ContainsKey(sci.modKey1.ToLower()) ? ModKeyDefines[sci.modKey1.ToLower()] : 0; int modKey2 = ModKeyDefines.ContainsKey(sci.modKey2.ToLower()) ? ModKeyDefines[sci.modKey2.ToLower()] : 0; int modKey3 = ModKeyDefines.ContainsKey(sci.modKey3.ToLower()) ? ModKeyDefines[sci.modKey3.ToLower()] : 0; Keys key = Keys.Escape; Keys.TryParse(sci.key, false, out key); RegisterHotKey(WinHandleToNum, sci.id, modKey1 | modKey2 | modKey3, (int)key); } }