public static void CallHotkey(Hotkey hotkey, HKID hkID, ref bool hkOK, Action hkAction) { bool once = false; if (!hotkey.Double) { once = true; } if (hotkey.ID == (int)hkID && hotkey.Enabled) { if (hkOK || once) { Logging.Log("Hotkey [" + Enum.GetName(typeof(HKID), hkID) + "] fired."); if (MahouUI.BlockHKWithCtrl && ContainsModifier((int)hotkey.Modifiers, (int)WinAPI.MOD_CONTROL)) { } else { if (hotkey.Modifiers > 0 && MahouUI.RePress) { KMHook.hotkeywithmodsfired = true; KMHook.RePressAfter(Convert.ToInt32(hotkey.Modifiers)); } } if (hotkey.ID <= (int)Hotkey.HKID.TransliterateSelection || hotkey.ID == (int)Hotkey.HKID.ShowSelectionTranslation || hotkey.ID == (int)Hotkey.HKID.CycleCase ) { KMHook.SendModsUp(Convert.ToInt32(hotkey.Modifiers)); } KMHook.IfKeyIsMod((System.Windows.Forms.Keys)hotkey.VirtualKeyCode); hkAction(); if (MahouUI.RePress) { KMHook.RePress(); } } else if (hotkey.Double) { Logging.Log("Waiting for second hotkey [" + Enum.GetName(typeof(HKID), hkID) + "] press."); hkOK = true; KMHook.doublekey.Interval = MMain.mahou.DoubleHKInterval; KMHook.doublekey.Start(); } } }
void load() // Loads configurations { MMain.mahou.IfNotExist(); try { cbLCLocalesList.SelectedIndex = String.IsNullOrEmpty(MMain.MyConfs.Read("ExtCtrls", "LCLocaleName")) ? 0 : MMain.lcnmid.IndexOf(MMain.MyConfs.Read("ExtCtrls", "LCLocaleName") + "(" + MMain.MyConfs.Read("ExtCtrls", "LCLocale") + ")"); cbRCLocalesList.SelectedIndex = String.IsNullOrEmpty(MMain.MyConfs.Read("ExtCtrls", "RCLocaleName")) ? 1 : MMain.lcnmid.IndexOf(MMain.MyConfs.Read("ExtCtrls", "RCLocaleName") + "(" + MMain.MyConfs.Read("ExtCtrls", "RCLocale") + ")"); } catch { MessageBox.Show(MMain.Msgs[9], MMain.Msgs[5], MessageBoxButtons.OK, MessageBoxIcon.Exclamation); RefreshLocales(); cbLCLocalesList.SelectedIndex = 0; cbRCLocalesList.SelectedIndex = 1; } cbUseLRC.Checked = MMain.MyConfs.ReadBool("ExtCtrls", "UseExtCtrls"); cbSymIgn.Checked = MMain.MyConfs.ReadBool("EnabledHotkeys", "HKSymIgnEnabled"); cbMoreTries.Checked = MMain.MyConfs.ReadBool("Functions", "MoreTries"); nudMTCount.Value = MMain.MyConfs.ReadInt("Functions", "TriesCount"); nudRefreshRate.Value = MMain.MyConfs.ReadInt("Functions", "DLRefreshRate"); cbDisplayLang.Checked = MMain.MyConfs.ReadBool("Functions", "DisplayLang"); btCol1.BackColor = ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLForeColor")); btCol2.BackColor = ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLBackColor")); cbExCSSwitch.Checked = MMain.MyConfs.ReadBool("Functions", "ExperimentalCSSwitch"); cbUseSnippets.Checked = MMain.MyConfs.ReadBool("Functions", "Snippets"); nudTTHeight.Value = MMain.MyConfs.ReadInt("TTipUI", "Height"); nudTTWidth.Value = MMain.MyConfs.ReadInt("TTipUI", "Width"); btFont.Font = (Font)fcv.ConvertFromString(MMain.MyConfs.Read("TTipUI", "Font")); nudXpos.Value = MMain.MyConfs.ReadInt("TTipUI", "xpos"); nudYpos.Value = MMain.MyConfs.ReadInt("TTipUI", "ypos"); cbTrBLT.Checked = MMain.MyConfs.ReadBool("TTipUI", "TransparentBack"); nudDoubleDelay.Value = MMain.MyConfs.ReadInt("DoubleKey", "Delay"); cbDoublePress.Checked = MMain.MyConfs.ReadBool("DoubleKey", "Use"); cbOnChange.Checked = MMain.MyConfs.ReadBool("Functions", "DTTOnChange"); cbScrollLight.Checked = MMain.MyConfs.ReadBool("Functions", "ScrollTip"); cbCheckForUPD.Checked = MMain.MyConfs.ReadBool("Functions", "UpdatesEnabled"); cbLogging.Checked = MMain.MyConfs.ReadBool("Functions", "Logging"); if (File.Exists(snipfile)) { tbSnippets.Text = File.ReadAllText(snipfile); KMHook.ReInitSnippets(); } Logging.Log("More Configs configurations loaded."); }
[STAThread] //DO NOT REMOVE THIS public static void Main(string[] args) { using (var mutex = new Mutex(false, "Global\\" + appGUid)) { if (!mutex.WaitOne(0, false)) { KMHook.PostMessage((IntPtr)0xffff, ao, 0, 0); return; } if (locales.Length < 2) { Locales.IfLessThan2(); } else { mahou = new MahouForm(); InitLanguage(); //Refreshes icon text language at startup mahou.icon.RefreshText(MMain.UI[44], MMain.UI[42], MMain.UI[43]); KMHook.ReInitSnippets(); Application.EnableVisualStyles(); // Huh i did not noticed that it was missing... '~' if (args.Length != 0) { if (args[0] == "_!_updated_!_") { mahou.ToggleVisibility(); MessageBox.Show(Msgs[0], Msgs[1], MessageBoxButtons.OK, MessageBoxIcon.Information); } } StartHook(); //for first run, add your locale 1 & locale 2 to settings if (MyConfs.Read("Locales", "locale1Lang") == "" && MyConfs.Read("Locales", "locale2Lang") == "") { MyConfs.Write("Locales", "locale1uId", locales[0].uId.ToString()); MyConfs.Write("Locales", "locale2uId", locales[1].uId.ToString()); MyConfs.Write("Locales", "locale1Lang", locales[0].Lang); MyConfs.Write("Locales", "locale2Lang", locales[1].Lang); } Application.Run(); StopHook(); } } }
/// <summary> /// values: /// [LAlt],[RAlt],[LShift],[RShift],[LCtrl],[RCtrl],[LWin],[RWin],[Key_Code] /// </summary> /// <param name="trhk"> raw hotkey from tray menu Mahou.mm</param> /// <returns></returns> public static Tuple <bool, bool, bool, bool, bool, bool, bool, Tuple <bool, int> > tray_hk_parse(string trhk) { bool la, ra, ls, rs, lc, rc, lw, rw; int kc = 0; la = ra = ls = rs = lc = rc = lw = rw = false; var p = trhk.ToLower().Substring(2, trhk.Length - 2).Split('+'); foreach (var x in p) { switch (x) { case "lalt": la = true; break; case "ralt": ra = true; break; case "lshift": ls = true; break; case "rshift": rs = true; break; case "lctrl": lc = true; break; case "rctrl": rc = true; break; case "lwin": lw = true; break; case "rwin": rw = true; break; default: // System.Diagnostics.Debug.WriteLine("x = " +x); if (!string.IsNullOrEmpty(x)) { var l = KMHook.strparsekey(x); if (l.Count > 0) { kc = (int)l[0]; } } break; } } return(new Tuple <bool, bool, bool, bool, bool, bool, bool, Tuple <bool, int> >(la, ra, ls, rs, lc, rc, lw, new Tuple <bool, int>(rw, kc))); }
static IntPtr jklWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { if (msg == jkluMSG) { uint layout = (uint)lParam; MahouUI.GlobalLayout = MahouUI.currentLayout = layout; Logging.Log("[JKL] > Layout changed to [" + layout + "] / [0x" + layout.ToString("X") + "]."); Debug.WriteLine(">> JKL LC: " + layout); Logging.Log("[JKL] > On layout act:" + OnLayoutAction); Logging.Log("[JKL] > ACtion: " + (ActionOnLayout == null?"null":ActionOnLayout.Method.Name)); if (layout == OnLayoutAction) { OnLayoutAction = 0; Debug.WriteLine("Executing action: " + ActionOnLayout.Method.Name + " on layout: " + layout); ActionOnLayout(); ActionOnLayout = null; actionOnLayoutExecuted = true; } if (start_cyclEmuSwitch) { if (layout != cycleEmuDesiredLayout) { KMHook.CycleEmulateLayoutSwitch(); } else { start_cyclEmuSwitch = false; } } else if (!self_change) { MahouUI.RefreshFLAG(); MMain.mahou.RefreshAllIcons(); MMain.mahou.UpdateLDs(); } } return(WinAPI.DefWindowProcW(hWnd, msg, wParam, lParam)); }
public void AddTranslation(GTResp gtr) { txt_Source.Text = gtr.source; if (TRANSCRIPTION) { if (!string.IsNullOrEmpty(gtr.src_transcr)) { var txt = new MahouUI.TextBoxCA(); txt.Name = txtstrc; txt.Multiline = true; if (this.Controls.ContainsKey(txtstrc)) { txt = (MahouUI.TextBoxCA) this.Controls[txtstrc]; } else { this.Controls.Add(txt); } txt.Text = "[" + MahouUI.UnescapeUnicode(gtr.src_transcr) + "]"; } else { if (this.Controls.ContainsKey(txtstrc)) { this.Controls.Remove(this.Controls[txtstrc]); } } } pan_Translations.Width = Width - 2; bool exist = false; if (GTRs.Count == 0) { pan_Translations.Height = 0; } if (!String.IsNullOrEmpty(MahouUI.AutoCopyTranslation)) { if (MahouUI.AutoCopyTranslation.ToLower() == gtr.targ_lang.ToLower()) { Debug.WriteLine("AutoCopyTranslation: " + gtr.targ_lang); KMHook.RestoreClipBoard(gtr.translation); MahouUI.ACT_Match++; } } foreach (Control ct in pan_Translations.Controls) { if (ct.Name == "PN_LINE_" + gtr.src_lang + ".to." + gtr.targ_lang) { exist = true; break; } } if (exist) { UpdateTranslation(gtr); } else { GTRs.Add(gtr); var ind = GTRs.IndexOf(gtr); var pan = new Panel(); pan.Width = pan_Translations.Width - 2; pan.Height = MahouUI.TrText.Height * 2; Debug.WriteLine("Pan height: " + pan.Height); pan.Name = "PN_LINE_" + gtr.src_lang + ".to." + gtr.targ_lang; pan.Location = new Point(1, pan_Translations.Height + 1); var slt = new MahouUI.TextBoxCA(); var txt = new MahouUI.TextBoxCA(); slt.ReadOnly = txt.ReadOnly = true; slt.TabStop = txt.TabStop = false; slt.Name = "SL_TXT" + gtr.targ_lang; slt.BorderStyle = txt.BorderStyle = 0; slt.Location = new Point(1, 0); slt.Text = (gtr.auto_detect ? "" : gtr.src_lang + "/") + gtr.targ_lang + ":"; var g = CreateGraphics(); var size = g.MeasureString(slt.Text, slt.Font); slt.Width = (int)size.Width; txt.Name = "TR_TXT" + gtr.targ_lang; txt.Text = MahouUI.UnescapeUnicode(gtr.translation); var btn = new ButtonLabel(); btn.Text = "♫"; btn.gtr = gtr; btn.Name = "LBBT_SP" + gtr.targ_lang; btn.Width = 14; btn.Height = 14; pan.Controls.Add(slt); pan.Controls.Add(txt); var trcw = 0; if (TRANSCRIPTION) { if (!String.IsNullOrEmpty(gtr.targ_transcr)) { MahouUI.TextBoxCA txttrc = new MahouUI.TextBoxCA(); txttrc.ReadOnly = true; txttrc.TabStop = false; txttrc.BorderStyle = 0; txttrc.Multiline = true; txttrc.Font = MahouUI.TrText; txttrc.Name = "TRC_TXT" + gtr.targ_lang; txttrc.Text = "[" + MahouUI.UnescapeUnicode(gtr.targ_transcr) + "]"; var si = g.MeasureString(txttrc.Text, txttrc.Font); trcw = txttrc.Width = (int)si.Width; txttrc.Location = new Point(txt.Location.X + pan.Width - slt.Width - 2 - btn.Width - 2 - trcw, txt.Location.Y); pan.Controls.Add(txttrc); } } g.Dispose(); btn.Location = new Point(pan.Width - 14 - 1, 1); pan.Controls.Add(btn); txt.Width = pan.Width - slt.Width - 2 - btn.Width - 2 - trcw; txt.Multiline = true; txt.Location = new Point(slt.Width + 2, 1); btn.BackColor = slt.BackColor = txt.BackColor = pan_Translations.BackColor; btn.ForeColor = slt.ForeColor = txt.ForeColor = pan_Translations.ForeColor; pan_Translations.Controls.Add(pan); txt_Source.Font = slt.Font = txt.Font = MahouUI.TrText; UpdateHeight(); } SetOptimalWidth(); SetOptimalWidth(); }
[STAThread] //DO NOT REMOVE THIS public static void Main(string[] args) { Application.EnableVisualStyles(); // at first enable styles. //Catch any error during program runtime AppDomain.CurrentDomain.UnhandledException += (obj, arg) => { var e = (Exception)arg.ExceptionObject; Logging.Log("Unexpected error occurred, Mahou exited, error details:\r\n" + e.Message + "\r\n" + e.StackTrace, 1); }; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); if (System.Globalization.CultureInfo.InstalledUICulture.TwoLetterISOLanguageName == "ru") { Lang = Languages.Russian; } MyConfs = new Configs(); if (Configs.forceAppData && Configs.fine) { MyConfs.Write("Functions", "AppDataConfigs", "true"); } Logging.Log("Mahou started."); using (var mutex = new Mutex(false, GGPU_Mutex)) { if (!mutex.WaitOne(0, false)) { if (args.Length > 0) { var arg1 = args[0].ToUpper(); if (arg1.StartsWith("/R") || arg1.StartsWith("-R") || arg1.StartsWith("R")) { WinAPI.PostMessage((IntPtr)0xffff, re, 0, 0); return; } } WinAPI.PostMessage((IntPtr)0xffff, ao, 0, 0); return; } if (MMain.MyConfs.ReadBool("Functions", "AppDataConfigs")) { var mahou_folder_appd = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mahou"); if (!Directory.Exists(mahou_folder_appd)) { Directory.CreateDirectory(mahou_folder_appd); } if (!File.Exists(Path.Combine(mahou_folder_appd, "Mahou.ini"))) // Copy main configs to appdata { File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mahou.ini"), Path.Combine(mahou_folder_appd, "Mahou.ini"), true); } Configs.filePath = Path.Combine(mahou_folder_appd, "Mahou.ini"); MyConfs = new Configs(); } else { Configs.filePath = Path.Combine(MahouUI.nPath, "Mahou.ini"); } MahouUI.latest_save_dir = Configs.filePath; if (MyConfs.ReadBool("FirstStart", "First")) { if (System.Globalization.CultureInfo.InstalledUICulture.TwoLetterISOLanguageName == "ru") { MyConfs.WriteSave("Appearence", "Language", "Русский"); MahouUI.InitLanguage(); MyConfs.WriteSave("Layouts", "SpecificLayout1", Lang[Languages.Element.SwitchBetween]); MyConfs.WriteSave("FirstStart", "First", "False"); } } else { MahouUI.InitLanguage(); } RefreshLCnMID(); //for first run, add your locale 1 & locale 2 to settings if (MyConfs.Read("Layouts", "MainLayout1") == "" && MyConfs.Read("Layouts", "MainLayout2") == "") { Logging.Log("Initializing locales."); MyConfs.Write("Layouts", "MainLayout1", lcnmid[0]); if (lcnmid.Count > 1) { MyConfs.Write("Layouts", "MainLayout2", lcnmid[1]); } MyConfs.WriteToDisk(); } mahou = new MahouUI(); rif = new RawInputForm(); Locales.IfLessThan2(); if (MyConfs.Read("Layouts", "MainLayout1") == "" && MyConfs.Read("Layouts", "MainLayout2") == "") { mahou.cbb_MainLayout1.SelectedIndex = 0; if (lcnmid.Count > 1) { mahou.cbb_MainLayout2.SelectedIndex = 1; } } _evt_hookID = WinAPI.SetWinEventHook(WinAPI.EVENT_SYSTEM_FOREGROUND, WinAPI.EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, _evt_proc, 0, 0, WinAPI.WINEVENT_OUTOFCONTEXT); _LDevt_hookID = WinAPI.SetWinEventHook(WinAPI.EVENT_OBJECT_FOCUS, WinAPI.EVENT_OBJECT_FOCUS, IntPtr.Zero, _LDevt_proc, 0, 0, WinAPI.WINEVENT_OUTOFCONTEXT); if (args.Length != 0) { if (args[0] == "_!_updated_!_") { Logging.Log("Mahou updated."); mahou.ToggleVisibility(); MessageBox.Show(Lang[Languages.Element.UpdateComplete], Lang[Languages.Element.UpdateComplete], MessageBoxButtons.OK, MessageBoxIcon.Information); } if (args[0] == "_!_silent_updated_!_") { Logging.Log("Mahou silently updated."); mahou.icon.trIcon.Visible = true; mahou.icon.trIcon.ShowBalloonTip(1000, Lang[Languages.Element.UpdateComplete], "Mahou -> " + mahou.Text, ToolTipIcon.Info); mahou.icon.trIcon.BalloonTipClicked += (_, __) => mahou.ToggleVisibility(); if (!mahou.TrayIconVisible) { KMHook.DoLater(() => mahou.Invoke((MethodInvoker) delegate { mahou.icon.trIcon.Visible = false; }), 1005); } } } MyConfs.WriteToDisk(); if (!string.IsNullOrEmpty(mahou.MainLayout1)) { MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetLocaleFromString(mahou.MainLayout1).uId; } Application.Run(); } }
public static IntPtr Callback(int nCode, IntPtr wParam, IntPtr lParam) { if (MMain.mahou == null || nCode < 0) { return(WinAPI.CallNextHookEx(_LLHook_ID, nCode, wParam, lParam)); } if (KMHook.ExcludedProgram() && !MahouUI.ChangeLayoutInExcluded) { return(WinAPI.CallNextHookEx(_LLHook_ID, nCode, wParam, lParam)); } var vk = Marshal.ReadInt32(lParam); var Key = (Keys)vk; if (MahouUI.BlockAltUpNOW) { if ((wParam == (IntPtr)WinAPI.WM_SYSKEYUP || wParam == (IntPtr)WinAPI.WM_KEYUP) && (Key == Keys.LMenu || Key == Keys.RMenu || Key == Keys.Menu)) { Debug.WriteLine("ihihihihihihihih-hihih-hi blocked alt :)))))"); MahouUI.BlockAltUpNOW = false; return((IntPtr)1); } } SetModifs(Key, wParam); if ((alt || alt) && (shift || shift_r) && Key == Keys.Tab) // mysterious Alt+Shift+Tab, sends Shift Up before Tab down!? { KMHook.skip_kbd_events++; } Debug.WriteLine("Alive" + vk + " :: " + wParam); #region Redefines if (redefines.len > 0) { var modsstr = KMHook.GetModsStr(ctrl, ctrl_r, shift, shift_r, alt, alt_r, win, win_r).Replace("+", " ").Replace(" ", "").ToLower(); for (int i = 0; i != redefines.len; i++) { if (Key == redefines[i].k) { Logging.Log("[REDEF] > Redefined: " + redefines[i].k + " => " + redefines[i].v); var rli = redefines_excl_mods[i].ToLower(); var redy = true; if (rli == "all" && !(!shift && !alt && !ctrl && !win && !shift_r && !alt_r && !ctrl_r && !win_r)) { redy = false; } else { var srli = rli.Split(' '); for (int y = 0; y != srli.Length; y++) { if (!String.IsNullOrEmpty(srli[y]) && modsstr.Contains(srli[y])) { Logging.Log("[REDEF] > Contains the modifier: " + srli[y]); redy = false; break; } } } if (redy) { KMHook.KeybdEvent(redefines[i].v, (wParam.ToInt32() == WinAPI.WM_KEYDOWN || wParam.ToInt32() == WinAPI.WM_SYSKEYDOWN) ? 0 : 2); return((IntPtr)1); } else { Logging.Log("[REDEF] > Redefine cancelled: by mods: " + redefines_excl_mods[i] + " (" + modsstr + ")"); } } } } #endregion #region Mahou.mm Tray Hotkeys var x = new Tuple <bool, bool, bool, bool, bool, bool, bool, Tuple <bool, int> >(alt, alt_r, shift, shift_r, ctrl, ctrl_r, win, new Tuple <bool, int>(win_r, vk)); // Debug.WriteLine("x_hk: " + Hotkey.tray_hk_to_string(x)); // Debug.WriteLine("dhk_wait: " +dhk_tray_wait); // Debug.WriteLine("dhk_hk: " +dhk_tray_hk); if (dhk_tray_wait) { var hk = Hotkey.tray_hk_parse(dhk_tray_hk); var UpOrDown = OnUpOrDown((Keys)hk.Rest.Item2, wParam); if (UpOrDown) { var eq = Hotkey.cmp_hotkey(hk, x); // Debug.WriteLine("dhk_eq: "+eq); if (eq) { Logging.Log("[TR_HK] > Executing action of (double)hotkey: " + dhk_tray_hk_real + " on second hotkey: " + dhk_tray_hk); KMHook.DoSelf(dhk_tray_act, "tray_hotkeys_double"); dhk_unset(); KMHook.SendModsUp(15, false); // less overkill when whole hotkey is being hold return((IntPtr)1); } } } else { for (int i = 0; i != MahouUI.tray_hotkeys.len; i++) { var hk = Hotkey.tray_hk_parse(MahouUI.tray_hotkeys[i].k); var UpOrDown = OnUpOrDown((Keys)hk.Rest.Item2, wParam); // Debug.WriteLine((UpOrDown ? "UP":"DOWN") + " key: " +Key); if (UpOrDown) { if (Hotkey.cmp_hotkey(hk, x)) { var d = Hotkey.tray_hk_is_double(MahouUI.tray_hotkeys[i].k); if (d.Item1) { dhk_tray_wait = true; dhk_tray_hk = d.Item3; dhk_tray_act = MahouUI.tray_hotkeys[i].v.Item1; dhk_tray_hk_real = MahouUI.tray_hotkeys[i].k; if (dhk_timer != null) { dhk_timer.Stop(); dhk_timer.Dispose(); } dhk_timer = new Timer(); dhk_timer.Interval = d.Item2; dhk_timer.Tick += (_, __) => { Debug.WriteLine("Unset timer dhk! " + dhk_timer.Interval + "ms"); dhk_unset(); dhk_timer.Stop(); dhk_timer.Dispose(); }; dhk_timer.Start(); } else { Logging.Log("[TR_HK] > Executing action of hotkey: " + MahouUI.tray_hotkeys[i].k); dhk_unset(); if (MahouUI.tray_hotkeys[i].v.Item2.Contains("hk|c") || MahouUI.tray_hotkeys[i].v.Item2.Contains("hk|s")) { var altl = ((hk.Item1 || hk.Rest.Item2 == (int)Keys.LMenu) && !hk.Item2 && // l alt not r alt !hk.Item3 && !hk.Item4 && !hk.Item5 && !hk.Item6 && !hk.Item7 && !hk.Rest.Item1); var altr = (!hk.Item1 && (hk.Item2 || hk.Rest.Item2 == (int)Keys.RMenu) && !hk.Item3 && !hk.Item4 && !hk.Item5 && !hk.Item6 && !hk.Item7 && !hk.Rest.Item1); if (altl || altr) { if (Locales.ActiveWindowClassName(40).Contains("Chrome_WidgetWin")) { MahouUI.chrome_window_alt_fix(); } } else { KMHook.SendModsUp(15, false); // less overkill when whole hotkey is being hold } if (altl) { KMHook.KeybdEvent(Keys.LMenu, 0); KMHook.KeybdEvent(Keys.LMenu, 2); } if (altr) { KMHook.KeybdEvent(Keys.RMenu, 0); KMHook.KeybdEvent(Keys.RMenu, 2); } if ((!hk.Item1 && !hk.Item2 && !hk.Item3 && !hk.Item4 && !hk.Item5 && !hk.Item6 && (hk.Item7 || hk.Rest.Item2 == (int)Keys.LWin) && !hk.Rest.Item1)) { KMHook.KeybdEvent(Keys.LWin, 0); KMHook.KeybdEvent(Keys.LWin, 2); } if ((!hk.Item1 && !hk.Item2 && !hk.Item3 && !hk.Item4 && !hk.Item5 && !hk.Item6 && !hk.Item7 && (hk.Rest.Item1 || hk.Rest.Item2 == (int)Keys.RWin))) { KMHook.KeybdEvent(Keys.RWin, 0); KMHook.KeybdEvent(Keys.RWin, 2); } } KMHook.DoSelf(MahouUI.tray_hotkeys[i].v.Item1, "tray_hotkeys"); return((IntPtr)1); } } } } } #endregion if (MahouUI.SnippetsEnabled) { if (KMHook.c_snip.Count > 0) { var t = MMain.mahou.SnippetsExpandType == "Tab"; if (t && Key == Keys.Tab && !shift && !alt && !win && !ctrl && !shift_r && !alt_r && !ctrl_r && !win_r) { WinAPI.keybd_event((byte)Keys.F14, (byte)Keys.F14, 0, 0); return((IntPtr)1); // Disable event } if (!t && MMain.mahou.SnippetsExpandType != "Space" && wParam == (IntPtr)WinAPI.WM_KEYDOWN || wParam == (IntPtr)WinAPI.WM_SYSKEYDOWN) { var ms = KMHook.GetModsStr(ctrl, ctrl_r, shift, shift_r, alt, alt_r, win, win_r); ms += Key; var othmatch = ms == MMain.mahou.SnippetsExpKeyOther; Debug.WriteLine("Checking SnippetsExpOther: [" + ms + "] == [" + MMain.mahou.SnippetsExpKeyOther + "] => " + othmatch); if (othmatch) { KMHook.ClearModifiers(); WinAPI.keybd_event((byte)Keys.F20, (byte)Keys.F20, 0, 0); return((IntPtr)1); } } } } if (MahouUI.RemapCapslockAsF18) { bool _shift = !shift, _alt = !alt, _ctrl = !ctrl, _win = !win, _shift_r = !shift_r, _alt_r = !alt_r, _ctrl_r = !ctrl_r, _win_r = !win_r; if (Key == Keys.CapsLock) { for (int i = 1; i != 5; i++) { var KeyIndex = (int)typeof(MahouUI).GetField("Key" + i).GetValue(MMain.mahou); if (KeyIndex == 8) // Shift+CapsLock { _shift = shift; _shift_r = shift_r; } } } uint mods = 0; if (alt || alt_r) { mods += WinAPI.MOD_ALT; } if (ctrl || ctrl_r) { mods += WinAPI.MOD_CONTROL; } if (shift || shift_r) { mods += WinAPI.MOD_SHIFT; } if (win || win_r) { mods += WinAPI.MOD_WIN; } bool has = MMain.mahou.HasHotkey(new Hotkey(false, (uint)Keys.F18, mods, 77)); if (has) { if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_SHIFT)) { _shift = shift; } _shift_r = shift_r; if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_ALT)) { _alt = alt; } _alt_r = alt_r; if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_CONTROL)) { _ctrl = ctrl; } _ctrl_r = ctrl_r; if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_WIN)) { _win = win; } _win_r = win_r; } var GJIME = false; if (vk >= 240 && vk <= 242) // GJ IME's Shift/Alt/Ctrl + CapsLock { GJIME = true; } // Debug.WriteLine(Key + " " +has + "// " + _shift + " " + _alt + " " + _ctrl + " " + _win + " " + mods + " >> " + (Key == Keys.CapsLock && _shift && _alt && _ctrl && _win)); if ((Key == Keys.CapsLock || GJIME) && _shift && _alt && _ctrl && _win && _shift_r && _alt_r && _ctrl_r && _win_r) { var flags = (int)(KInputs.IsExtended(Key) ? WinAPI.KEYEVENTF_EXTENDEDKEY : 0); if (wParam == (IntPtr)WinAPI.WM_KEYUP) { flags |= (int)WinAPI.KEYEVENTF_KEYUP; } WinAPI.keybd_event((byte)Keys.F18, (byte)Keys.F18, flags, 0); return((IntPtr)1); // Disable event } // Debug.WriteLine(Marshal.GetLastWin32Error()); } return(WinAPI.CallNextHookEx(_LLHook_ID, nCode, wParam, lParam)); }
public static void Init() { if (!MahouUI.ENABLED) { return; } if (running) { bool exist = true; if (Environment.Is64BitOperatingSystem) { if (Process.GetProcessesByName("jkl").Length > 0) { Logging.Log("[JKL] > JKL already running."); } else { exist = false; } } else { if (Process.GetProcessesByName("jklx86").Length > 0) { Logging.Log("[JKL] > JKLx86 already running."); } else { exist = false; } } if (!exist) { Logging.Log("[JKL] > JKL seems closed, restarting..."); running = false; } } if (HWND == IntPtr.Zero) { Logging.Log("[JKL] > Initializing JKL HWND server..."); WNDPROC_DELEGATE = jklWndProc; var wnd_class = new WinAPI.WNDCLASS(); wnd_class.lpszClassName = "_XHIDDEN_HWND_SERVER"; wnd_class.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(WNDPROC_DELEGATE); UInt16 cls_reg = WinAPI.RegisterClassW(ref wnd_class); int last_error = Marshal.GetLastWin32Error(); if (cls_reg == 0 && last_error != 0) { Logging.Log("[JKL] > Could not register window class, for jkl Hidden Server, err: " + last_error, 1); } HWND = WinAPI.CreateWindowExW(0, "_XHIDDEN_HWND_SERVER", "_XHIDDEN_HWND_SERVER", 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); Logging.Log("[JKL] > SERVER HWND: " + HWND); } if (!running) { if (jklExist()) { if (Environment.Is64BitOperatingSystem) { Logging.Log("[JKL] > Starting jkl.exe..."); var jkl = new ProcessStartInfo(); jkl.UseShellExecute = true; jkl.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jkl.exe"); jkl.WorkingDirectory = Path.Combine(Path.GetTempPath()); Process.Start(jkl); } else { Logging.Log("[JKL] > Starting \"jklx86.exe -msg\"..."); var jkl = new ProcessStartInfo(); jkl.UseShellExecute = true; jkl.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jklx86.exe"); jkl.Arguments = "-msg"; jkl.WorkingDirectory = Path.Combine(Path.GetTempPath()); Process.Start(jkl); } var umsgID = Path.Combine(Path.GetTempPath(), "umsg.id"); var tries = 0; while (!File.Exists(umsgID)) { Thread.Sleep(350); tries++; if (tries > 20) { Logging.Log("[JKL] > Error, umsg.id not found after 20 tries by 350 ms timeout.", 1); Destroy(); break; } } if (tries <= 20) { Logging.Log("[JKL] > umsg.id found, after " + tries + " tries * 350ms timeout."); Logging.Log("[JKL] > Retrieving umsg.id..."); jkluMSG = Int32.Parse(File.ReadAllText(umsgID)); File.Delete(umsgID); // KMHook.DoLater(() => CycleAllLayouts(Locales.ActiveWindow()), 350); KMHook.DoLater(() => { MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetCurrentLocale(); }, 200); running = true; } } else { Logging.Log("[JKL] > " + jklInfoStr, 1); } if (jkluMSG == -1) { KMHook.JKLERR = true; } else { KMHook.JKLERR = false; } Logging.Log("[JKL] > Init done, umsg: [" + jkluMSG + "], JKLXServ: [" + HWND + "]."); } }
static IntPtr jklWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { if (msg == jkluMSG) { uint layout = (uint)lParam, laysho = layout & 0xffff; MahouUI.GlobalLayout = MahouUI.currentLayout = layout; Logging.Log("[JKL] > Layout changed to [" + layout + "] / [0x" + layout.ToString("X") + "]."); Debug.WriteLine(">> JKL LC: " + layout); Logging.Log("[JKL] > On layout act:" + OnLayoutAction); var anull = ActionOnLayout == null; Logging.Log("[JKL] > ACtion: " + (anull?"null":ActionOnLayout.Method.Name)); if (layout == OnLayoutAction || (layout & 0xffff) == (OnLayoutAction & 0xffff)) { actionOnLayoutExecuted = true; OnLayoutAction = 0; if (anull) { Logging.Log("[JKL] > Action is null, something terribly went wrong... Please try to disable JKL, if layout changing went wild.", 1); } else { Debug.WriteLine("Executing action: " + ActionOnLayout.Method.Name + " on layout: " + layout); ActionOnLayout(); ActionOnLayout = null; } } if (start_cyclEmuSwitch) { Debug.WriteLine("Cycling out from: " + layout + " to " + cycleEmuDesiredLayout + "..."); if (layout != cycleEmuDesiredLayout && laysho != cycleEmuDesiredLayout) { KMHook.CycleEmulateLayoutSwitch(); } else { start_cyclEmuSwitch = false; } } if (!self_change && !start_cyclEmuSwitch) { MahouUI.RefreshFLAG(); MMain.mahou.RefreshAllIcons(); MMain.mahou.UpdateLDs(); if (anull && !KMHook.selfie && KMHook.AS_IGN_LS) { if (KMHook.AS_IGN_RULES.Contains("L")) { Debug.WriteLine("[HEY] > " + KMHook.was_ls); if (KMHook.was_ls) { KMHook.was_ls = KMHook.was_back = KMHook.was_del = false; } else { KMHook.was_ls = true; if (KMHook.AS_IGN_RULES.Contains("T")) { if (KMHook.AS_IGN_RESET != null) { KMHook.AS_IGN_RESET.Stop(); KMHook.AS_IGN_RESET.Dispose(); } KMHook.AS_IGN_RESET = new System.Windows.Forms.Timer(); KMHook.AS_IGN_RESET.Interval = KMHook.AS_IGN_TIMEOUT; KMHook.AS_IGN_RESET.Tick += (_, __) => { Debug.WriteLine("TIMER_AS_RESET"); KMHook.was_ls = KMHook.was_back = KMHook.was_del = false; KMHook.AS_IGN_RESET.Stop(); KMHook.AS_IGN_RESET.Dispose(); }; KMHook.AS_IGN_RESET.Start(); } } } else { KMHook.was_ls = true; } } } } return(WinAPI.DefWindowProcW(hWnd, msg, wParam, lParam)); }
void Save() // Saves configurations { MMain.mahou.IfNotExist(); var getname = new Regex("\\w+"); var getUID = new Regex("\\w+\\W(\\d+)"); MMain.MyConfs.Write("ExtCtrls", "LCLocaleName", getname.Match(cbLCLocalesList.Text).Value); MMain.MyConfs.Write("ExtCtrls", "RCLocaleName", getname.Match(cbRCLocalesList.Text).Value); MMain.MyConfs.Write("ExtCtrls", "LCLocale", getUID.Match(cbLCLocalesList.Text).Groups[1].Value); MMain.MyConfs.Write("ExtCtrls", "RCLocale", getUID.Match(cbRCLocalesList.Text).Groups[1].Value); MMain.MyConfs.Write("ExtCtrls", "UseExtCtrls", cbUseLRC.Checked.ToString()); MMain.MyConfs.Write("EnabledHotkeys", "HKSymIgnEnabled", cbSymIgn.Checked.ToString()); MMain.MyConfs.Write("Functions", "MoreTries", cbMoreTries.Checked.ToString()); MMain.MyConfs.Write("Functions", "TriesCount", nudMTCount.Value.ToString()); MMain.MyConfs.Write("Functions", "DLRefreshRate", nudRefreshRate.Value.ToString()); MMain.MyConfs.Write("Functions", "DisplayLang", cbDisplayLang.Checked.ToString()); MMain.MyConfs.Write("Functions", "DLForeColor", ColorTranslator.ToHtml(btCol1.BackColor)); MMain.MyConfs.Write("Functions", "DLBackColor", ColorTranslator.ToHtml(btCol2.BackColor)); MMain.MyConfs.Write("Functions", "ExperimentalCSSwitch", cbExCSSwitch.Checked.ToString()); MMain.MyConfs.Write("Functions", "Snippets", cbUseSnippets.Checked.ToString()); MMain.MyConfs.Write("TTipUI", "Height", nudTTHeight.Value.ToString()); MMain.MyConfs.Write("TTipUI", "Width", nudTTWidth.Value.ToString()); MMain.MyConfs.Write("TTipUI", "Font", fcv.ConvertToString(btFont.Font)); MMain.MyConfs.Write("TTipUI", "xpos", nudXpos.Value.ToString()); MMain.MyConfs.Write("TTipUI", "ypos", nudYpos.Value.ToString()); MMain.MyConfs.Write("TTipUI", "TransparentBack", cbTrBLT.Checked.ToString()); MMain.MyConfs.Write("Functions", "DTTOnChange", cbOnChange.Checked.ToString()); MMain.MyConfs.Write("Functions", "ScrollTip", cbScrollLight.Checked.ToString()); MMain.MyConfs.Write("Functions", "UpdatesEnabled", cbCheckForUPD.Checked.ToString()); MMain.mahou.langDisplay.ChangeColors(ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLForeColor")), ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLBackColor"))); MMain.mahou.langDisplay.ChangeSizes((Font)fcv.ConvertFromString(MMain.MyConfs.Read("TTipUI", "Font")), MMain.MyConfs.ReadInt("TTipUI", "Height"), MMain.MyConfs.ReadInt("TTipUI", "Width")); MMain.MyConfs.Write("DoubleKey", "Delay", nudDoubleDelay.Value.ToString()); MMain.MyConfs.Write("DoubleKey", "Use", cbDoublePress.Checked.ToString()); File.WriteAllText(snipfile, tbSnippets.Text); KMHook.ReInitSnippets(); MMain.mahou.langDisplay.SetVisInvis(); if (!string.IsNullOrEmpty(tmpSIMods) && tmpSIKey != 0) { MMain.MyConfs.Write("Hotkeys", "HKSymIgnMods", tmpSIMods); } if (tmpSIKey != 0) { MMain.MyConfs.Write("Hotkeys", "HKSymIgnKey", tmpSIKey.ToString()); } else { MessageBox.Show(MMain.Msgs[6], MMain.Msgs[5], MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (!string.IsNullOrEmpty(tempConMorWorMods) && tempConMorWorKey != 0) { MMain.MyConfs.Write("Hotkeys", "HKConvertMoreMods", tempConMorWorMods); } if (tempConMorWorKey != 0) { MMain.MyConfs.Write("Hotkeys", "HKConvertMore", tempConMorWorKey.ToString()); } else { MessageBox.Show(MMain.Msgs[6], MMain.Msgs[5], MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (MMain.MyConfs.ReadBool("Functions", "DisplayLang")) { MMain.mahou.ICheck.Start(); } else { MMain.mahou.ICheck.Stop(); } if (MMain.MyConfs.ReadBool("Functions", "ScrollTip")) { MMain.mahou.ScrlCheck.Start(); } else { MMain.mahou.ScrlCheck.Stop(); } MMain.mahou.ICheck.Interval = Convert.ToInt32(nudRefreshRate.Value); MMain.mahou.res.Interval = Convert.ToInt32(nudRefreshRate.Value) * 7; MMain.mahou.RefreshIconAll(); MMain.mahou.InitializeHotkeys(); }
public static IntPtr Callback(int nCode, IntPtr wParam, IntPtr lParam) { if (MMain.mahou == null || nCode < 0) { return(WinAPI.CallNextHookEx(_LLHook_ID, nCode, wParam, lParam)); } if (KMHook.ExcludedProgram() && !MahouUI.ChangeLayoutInExcluded) { return(WinAPI.CallNextHookEx(_LLHook_ID, nCode, wParam, lParam)); } var vk = Marshal.ReadInt32(lParam); var Key = (Keys)vk; if (MahouUI.BlockAltUpNOW) { if ((wParam == (IntPtr)WinAPI.WM_SYSKEYUP || wParam == (IntPtr)WinAPI.WM_KEYUP) && (Key == Keys.LMenu || Key == Keys.RMenu || Key == Keys.Menu)) { Debug.WriteLine("ihihihihihihihih-hihih-hi blocked alt :)))))"); MahouUI.BlockAltUpNOW = false; return((IntPtr)1); } } SetModifs(Key, wParam); Debug.WriteLine("Alive" + vk); #region Mahou.mm Tray Hotkeys if (wParam == (IntPtr)WinAPI.WM_KEYDOWN || wParam == (IntPtr)WinAPI.WM_SYSKEYDOWN) { for (int i = 0; i != MahouUI.tray_hotkeys.len; i++) { var x = new Tuple <bool, bool, bool, bool, bool, bool, bool, Tuple <bool, int> >(alt, alt_r, shift, shift_r, ctrl, ctrl_r, win, new Tuple <bool, int>(win_r, vk)); if (Hotkey.cmp_hotkey(Hotkey.tray_hk_parse(MahouUI.tray_hotkeys[i].k), x)) { Logging.Log("[TR_HK] > Executing action of hotkey: " + MahouUI.tray_hotkeys[i].k); KMHook.DoSelf(MahouUI.tray_hotkeys[i].v, "tray_hotkeys"); KMHook.SendModsUp(15, false); // less overkill when whole hotkey is being hold return((IntPtr)1); } } } #endregion if (MahouUI.SnippetsEnabled) { if (KMHook.c_snip.Count > 0) { if (MMain.mahou.SnippetsExpandType == "Tab" && Key == Keys.Tab && !shift && !alt && !win && !ctrl && !shift_r && !alt_r && !ctrl_r && !win_r) { WinAPI.keybd_event((byte)Keys.F14, (byte)Keys.F14, (int)WinAPI.KEYEVENTF_KEYUP, 0); return((IntPtr)1); // Disable event } } } if (MahouUI.RemapCapslockAsF18) { bool _shift = !shift, _alt = !alt, _ctrl = !ctrl, _win = !win, _shift_r = !shift_r, _alt_r = !alt_r, _ctrl_r = !ctrl_r, _win_r = !win_r; if (Key == Keys.CapsLock) { for (int i = 1; i != 5; i++) { var KeyIndex = (int)typeof(MahouUI).GetField("Key" + i).GetValue(MMain.mahou); if (KeyIndex == 8) // Shift+CapsLock { _shift = shift; } _shift_r = shift_r; } } uint mods = 0; if (alt || alt_r) { mods += WinAPI.MOD_ALT; } if (ctrl || ctrl_r) { mods += WinAPI.MOD_CONTROL; } if (shift || shift_r) { mods += WinAPI.MOD_SHIFT; } if (win || win_r) { mods += WinAPI.MOD_WIN; } bool has = MMain.mahou.HasHotkey(new Hotkey(false, (uint)Keys.F18, mods, 77)); if (has) { if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_SHIFT)) { _shift = shift; } _shift_r = shift_r; if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_ALT)) { _alt = alt; } _alt_r = alt_r; if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_CONTROL)) { _ctrl = ctrl; } _ctrl_r = ctrl_r; if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_WIN)) { _win = win; } _win_r = win_r; } var GJIME = false; if (vk >= 240 && vk <= 242) // GJ IME's Shift/Alt/Ctrl + CapsLock { GJIME = true; } // Debug.WriteLine(Key + " " +has + "// " + _shift + " " + _alt + " " + _ctrl + " " + _win + " " + mods + " >> " + (Key == Keys.CapsLock && _shift && _alt && _ctrl && _win)); if ((Key == Keys.CapsLock || GJIME) && _shift && _alt && _ctrl && _win && _shift_r && _alt_r && _ctrl_r && _win_r) { var flags = (int)(KInputs.IsExtended(Key) ? WinAPI.KEYEVENTF_EXTENDEDKEY : 0); if (wParam == (IntPtr)WinAPI.WM_KEYUP) { flags |= (int)WinAPI.KEYEVENTF_KEYUP; } WinAPI.keybd_event((byte)Keys.F18, (byte)Keys.F18, flags, 0); return((IntPtr)1); // Disable event } // Debug.WriteLine(Marshal.GetLastWin32Error()); } return(WinAPI.CallNextHookEx(_LLHook_ID, nCode, wParam, lParam)); }
// for debugging // public static string tray_hk_to_string(Tuple<bool, bool, bool, bool, bool, bool, bool, Tuple<bool, int>> trhk) { // var strhk = ""; // if(trhk.Item1) { strhk += "lalt+"; } // if(trhk.Item2) { strhk += "ralt+"; } // if(trhk.Item3) { strhk += "lshift+"; } // if(trhk.Item4) { strhk += "rshift+"; } // if(trhk.Item5) { strhk += "lctrl"; } // if(trhk.Item6) { strhk += "rctrl+"; } // if(trhk.Item7) { strhk += "lwin+"; } // if(trhk.Rest.Item1) { strhk += "rwin+"; } // strhk += ((Keys)trhk.Rest.Item2).ToString(); // return strhk; // } /// <summary> /// values: /// [LAlt],[RAlt],[LShift],[RShift],[LCtrl],[RCtrl],[LWin],[RWin],[Key_Code] /// </summary> /// <param name="trhk"> raw hotkey from tray menu Mahou.mm</param> /// <returns></returns> public static Tuple <bool, bool, bool, bool, bool, bool, bool, Tuple <bool, int> > tray_hk_parse(string trhk) { bool la, ra, ls, rs, lc, rc, lw, rw; int kc = 0; la = ra = ls = rs = lc = rc = lw = rw = false; if (trhk.Contains("&&")) { trhk = trhk.Split(new [] { "&&" }, StringSplitOptions.None)[0]; } var p = trhk.ToLower().Substring(2, trhk.Length - 2).Split('+'); foreach (var x in p) { // System.Diagnostics.Debug.WriteLine("X: " +x); switch (x) { case "lalt": la = true; break; case "ralt": ra = true; break; case "lshift": ls = true; break; case "rshift": rs = true; break; case "lctrl": lc = true; break; case "rctrl": rc = true; break; case "lwin": lw = true; break; case "rwin": rw = true; break; default: // System.Diagnostics.Debug.WriteLine("x = " +x); if (!string.IsNullOrEmpty(x)) { if (x.ToLower() == "laltkey") { kc = (int)Keys.LMenu; } else if (x.ToLower() == "raltkey") { kc = (int)Keys.LMenu; } else if (x.ToLower() == "lwinkey") { kc = (int)Keys.LWin; } else if (x.ToLower() == "rwinkey") { kc = (int)Keys.RWin; } else { var l = KMHook.strparsekey(x); if (l.Count > 0) { kc = (int)l[0]; } } } break; } } return(new Tuple <bool, bool, bool, bool, bool, bool, bool, Tuple <bool, int> >(la, ra, ls, rs, lc, rc, lw, new Tuple <bool, int>(rw, kc))); }
public static void Init() { if (!MahouUI.ENABLED) { return; } if (running) { bool exist = true; if (Environment.Is64BitOperatingSystem) { if (Process.GetProcessesByName("jkl").Length > 0) { Logging.Log("[JKL] > JKL already running."); } else { exist = false; } } else { if (Process.GetProcessesByName("jklx86").Length > 0) { Logging.Log("[JKL] > JKLx86 already running."); } else { exist = false; } } if (!exist) { Logging.Log("[JKL] > JKL seems closed, restarting..."); running = false; } } if (s == null) { Logging.Log("[JKL] > Initializing JKL HWND server..."); s = new HServer(); Logging.Log("[JKL] > SERVER HWND: " + s.Handle + " WinTitle: " + s.Text); } if (!running) { if (jklExist()) { if (Environment.Is64BitOperatingSystem) { Logging.Log("[JKL] > Starting jkl.exe..."); var jkl = new ProcessStartInfo(); jkl.UseShellExecute = true; jkl.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jkl.exe"); jkl.WorkingDirectory = Path.Combine(Path.GetTempPath()); Process.Start(jkl); } else { Logging.Log("[JKL] > Starting \"jklx86.exe -msg\"..."); var jkl = new ProcessStartInfo(); jkl.UseShellExecute = true; jkl.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jklx86.exe"); jkl.Arguments = "-msg"; jkl.WorkingDirectory = Path.Combine(Path.GetTempPath()); Process.Start(jkl); } var umsgID = Path.Combine(Path.GetTempPath(), "umsg.id"); var tries = 0; while (!File.Exists(umsgID)) { Thread.Sleep(350); tries++; if (tries > 20) { Logging.Log("[JKL] > Error, umsg.id not found after 20 tries by 350 ms timeout.", 1); Destroy(); break; } } if (tries <= 20) { Logging.Log("[JKL] > umsg.id found, after " + tries + " tries * 350ms timeout."); Logging.Log("[JKL] > Retrieving umsg.id..."); jkluMSG = Int32.Parse(File.ReadAllText(umsgID)); File.Delete(umsgID); // KMHook.DoLater(() => CycleAllLayouts(Locales.ActiveWindow()), 350); KMHook.DoLater(() => { MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetCurrentLocale(); }, 200); running = true; } } else { Logging.Log("[JKL] > " + jklInfoStr, 1); } if (jkluMSG == -1) { KMHook.JKLERR = true; } else { KMHook.JKLERR = false; } Logging.Log("[JKL] > Init done, umsg: [" + jkluMSG + "], JKLXServ: [" + s.Handle + "]."); } }
public static IntPtr Callback(int nCode, IntPtr wParam, IntPtr lParam) { if (MMain.mahou == null || nCode < 0) { return(WinAPI.CallNextHookEx(_LLHook_ID, nCode, wParam, lParam)); } if (KMHook.ExcludedProgram() && !MahouUI.ChangeLayoutInExcluded) { return(WinAPI.CallNextHookEx(_LLHook_ID, nCode, wParam, lParam)); } var vk = Marshal.ReadInt32(lParam); var Key = (Keys)vk; SetModifs(Key, wParam); if (MahouUI.SnippetsEnabled) { if (KMHook.c_snip.Count > 0) { if (MMain.mahou.SnippetsExpandType == "Tab" && Key == Keys.Tab && !shift && !alt && !win && !ctrl) { WinAPI.keybd_event((byte)Keys.F14, (byte)Keys.F14, (int)WinAPI.KEYEVENTF_KEYUP, 0); return((IntPtr)1); // Disable event } } } if (MahouUI.RemapCapslockAsF18) { bool _shift = !shift, _alt = !alt, _ctrl = !ctrl, _win = !win; if (Key == Keys.CapsLock) { for (int i = 1; i != 5; i++) { var KeyIndex = (int)typeof(MahouUI).GetField("Key" + i).GetValue(MMain.mahou); if (KeyIndex == 8) // Shift+CapsLock { _shift = shift; } } } uint mods = 0; if (alt) { mods += WinAPI.MOD_ALT; } if (ctrl) { mods += WinAPI.MOD_CONTROL; } if (shift) { mods += WinAPI.MOD_SHIFT; } if (win) { mods += WinAPI.MOD_WIN; } bool has = MMain.mahou.HasHotkey(new Hotkey(false, (uint)Keys.F18, mods, 77)); if (has) { if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_SHIFT)) { _shift = shift; } if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_ALT)) { _alt = alt; } if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_CONTROL)) { _ctrl = ctrl; } if (Hotkey.ContainsModifier((int)mods, (int)WinAPI.MOD_WIN)) { _win = win; } } var GJIME = false; if (vk >= 240 && vk <= 242) // GJ IME's Shift/Alt/Ctrl + CapsLock { GJIME = true; } // Debug.WriteLine(Key + " " +has + "// " + _shift + " " + _alt + " " + _ctrl + " " + _win + " " + mods + " >> " + (Key == Keys.CapsLock && _shift && _alt && _ctrl && _win)); if ((Key == Keys.CapsLock || GJIME) && _shift && _alt && _ctrl && _win) { var flags = (int)(KInputs.IsExtended(Key) ? WinAPI.KEYEVENTF_EXTENDEDKEY : 0); if (wParam == (IntPtr)WinAPI.WM_KEYUP) { flags |= (int)WinAPI.KEYEVENTF_KEYUP; } WinAPI.keybd_event((byte)Keys.F18, (byte)Keys.F18, flags, 0); return((IntPtr)1); // Disable event } // Debug.WriteLine(Marshal.GetLastWin32Error()); } return(WinAPI.CallNextHookEx(_LLHook_ID, nCode, wParam, lParam)); }
public MahouForm() { InitializeComponent(); res.Tick += (_, __) => { // Console.WriteLine("hiding"); onepass = true; langDisplay.HideWnd(); res.Stop(); }; res.Interval = ICheck.Interval * 4; ICheck.Tick += (_, __) => { if (MMain.MyConfs.ReadBool("Functions", "DTTOnChange")) { if (onepass) { latestL = Locales.GetCurrentLocale(); onepass = false; } if (latestL != Locales.GetCurrentLocale()) { langDisplay.ShowInactiveTopmost(); res.Start(); } } else { if (ICheckings.IsICursor()) { langDisplay.ShowInactiveTopmost(); } else { langDisplay.HideWnd(); } } langDisplay.Location = new Point(Cursor.Position.X + MMain.MyConfs.ReadInt("TTipUI", "xpos"), Cursor.Position.Y + MMain.MyConfs.ReadInt("TTipUI", "ypos")); langDisplay.RefreshLang(); }; ScrlCheck.Tick += (_, __) => { if (MMain.MyConfs.ReadBool("Functions", "ScrollTip") && !KMHook.self) { KMHook.self = true; if (Locales.GetCurrentLocale() == MMain.MyConfs.ReadInt("Locales", "locale1uId")) { if (!Control.IsKeyLocked(Keys.Scroll)) // Turn on { KMHook.KeybdEvent(Keys.Scroll, 0); KMHook.KeybdEvent(Keys.Scroll, 2); } } else { if (Control.IsKeyLocked(Keys.Scroll)) // Turn off { KMHook.KeybdEvent(Keys.Scroll, 0); KMHook.KeybdEvent(Keys.Scroll, 2); } } KMHook.self = false; } }; ScrlCheck.Interval = 250; if (MMain.MyConfs.ReadBool("Functions", "ScrollTip")) { ScrlCheck.Start(); } KMHook.doublekey.Tick += (_, __) => { if (KMHook.hklOK) { KMHook.hklOK = false; } if (KMHook.hksOK) { KMHook.hksOK = false; } if (KMHook.hklineOK) { KMHook.hklineOK = false; } if (KMHook.hkSIOK) { KMHook.hkSIOK = false; } KMHook.doublekey.Stop(); //Console.WriteLine("Timeout!"); }; langDisplay.ChangeColors(ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLForeColor")), ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLBackColor"))); langDisplay.ChangeSizes((Font)moreConfigs.fcv.ConvertFromString(MMain.MyConfs.Read("TTipUI", "Font")), MMain.MyConfs.ReadInt("TTipUI", "Height"), MMain.MyConfs.ReadInt("TTipUI", "Width")); ICheck.Interval = MMain.MyConfs.ReadInt("Functions", "DLRefreshRate"); if (MMain.MyConfs.ReadBool("Functions", "DisplayLang")) { ICheck.Start(); } icon = new TrayIcon(MMain.MyConfs.ReadBool("Functions", "IconVisibility")); icon.Exit += exitToolStripMenuItem_Click; icon.ShowHide += showHideToolStripMenuItem_Click; //↓ Dummy(none) hotkey, makes it possible WndProc to handle messages at startup //↓ when form isn't was shown. RegisterHotKey(Handle, 0xffff ^ 0xffff, 0, 0); //HWND must be this form handle RefreshIconAll(); InitializeHotkeys(); //Background startup check for updates if (MMain.MyConfs.ReadBool("Functions", "UpdatesEnabled")) { var uche = new System.Threading.Thread(update.StartupCheck); uche.Name = "Startup Check"; uche.Start(); } }
protected override void WndProc(ref Message m) { if (m.Msg == WinAPI.WM_INPUT) { WinAPI.RAWINPUT input = new WinAPI.RAWINPUT(); int outSize = 0; int size = Marshal.SizeOf(typeof(WinAPI.RAWINPUT)); outSize = WinAPI.GetRawInputData(m.LParam, WinAPI.RawInputCommand.Input, out input, ref size, Marshal.SizeOf(typeof(WinAPI.RAWINPUTHEADER))); if (outSize != -1) { if (input.Header.Type == WinAPI.RawInputType.Mouse) { if (input.Data.Mouse.Data.ButtonFlags != WinAPI.RawMouseButtons.None) { KMHook.ListenMouse(input.Data.Mouse.Data.ButtonFlags); } } if (input.Header.Type == WinAPI.RawInputType.Keyboard) { var kbd = input.Data.Keyboard; var k = kbd.VKey; switch (k) { case (int)Keys.ShiftKey: if (kbd.MakeCode == 42) { k = (int)Keys.LShiftKey; } else { k = (int)Keys.RShiftKey; } break; case (int)Keys.ControlKey: if (kbd.Flags < 2) { k = (int)Keys.LControlKey; } else { k = (int)Keys.RControlKey; } break; case (int)Keys.Menu: if (kbd.Flags < 2) { k = (int)Keys.LMenu; } else { k = (int)Keys.RMenu; } break; } KMHook.ListenKeyboard(k, input.Data.Keyboard.Message); } } } base.WndProc(ref m); }
[STAThread] //DO NOT REMOVE THIS public static void Main(string[] args) { Logging.Log("Mahou started."); //Catch any error during program runtime AppDomain.CurrentDomain.UnhandledException += (obj, arg) => { var e = (Exception)arg.ExceptionObject; Logging.Log("Unexpected error occurred, Mahou exited, error details:\r\n" + e.Message + "\r\n" + e.StackTrace, 1); }; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); using (var mutex = new Mutex(false, "Global\\" + appGUid)) { if (!mutex.WaitOne(0, false)) { WinAPI.PostMessage((IntPtr)0xffff, ao, 0, 0); return; } if (locales.Length < 2) { Logging.Log("Too less layouts/locales. Program will exit."); Locales.IfLessThan2(); } else { if (MyConfs.ReadBool("FirstStart", "First")) { if (System.Globalization.CultureInfo.InstalledUICulture.TwoLetterISOLanguageName == "ru") { MyConfs.Write("Appearence", "Language", "Русский"); MahouUI.InitLanguage(); MyConfs.Write("Layouts", "SpecificLayout1", Lang[Languages.Element.SwitchBetween]); MyConfs.Write("FirstStart", "First", "False"); } } else { MahouUI.InitLanguage(); } foreach (Locales.Locale lc in MMain.locales) { MMain.lcnmid.Add(lc.Lang + "(" + lc.uId + ")"); } //for first run, add your locale 1 & locale 2 to settings if (MyConfs.Read("Layouts", "MainLayout1") == "" && MyConfs.Read("Layouts", "MainLayout2") == "") { Logging.Log("Initializing locales."); MyConfs.Write("Layouts", "MainLayout1", lcnmid[0]); MyConfs.Write("Layouts", "MainLayout2", lcnmid[1]); } mahou = new MahouUI(); if (MyConfs.Read("Layouts", "MainLayout1") == "" && MyConfs.Read("Layouts", "MainLayout2") == "") { mahou.cbb_MainLayout1.SelectedIndex = 0; mahou.cbb_MainLayout2.SelectedIndex = 1; } //Refreshes icon text language at startup // mahou.icon.RefreshText(MMain.UI[44], MMain.UI[42], MMain.UI[43]); KMHook.ReInitSnippets(); Application.EnableVisualStyles(); // Huh i did not noticed that it was missing... '~' _evt_hookID = WinAPI.SetWinEventHook(WinAPI.EVENT_SYSTEM_FOREGROUND, WinAPI.EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, _evt_proc, 0, 0, WinAPI.WINEVENT_OUTOFCONTEXT); KMHook.CheckLayoutLater.Tick += (_, __) => { MahouUI.GlobalLayout = Locales.GetCurrentLocale(); KMHook.CheckLayoutLater.Stop(); }; if (args.Length != 0) { if (args[0] == "_!_updated_!_") { Logging.Log("Mahou updated."); mahou.ToggleVisibility(); MessageBox.Show(Lang[Languages.Element.UpdateComplete], Lang[Languages.Element.UpdateComplete], MessageBoxButtons.OK, MessageBoxIcon.Information); } } StartHook(); MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetLocaleFromString(mahou.MainLayout1).uId; Application.Run(); StopHook(); } } }