Example #1
0
 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);
         if (layout == OnLayoutAction)
         {
             OnLayoutAction = 0;
             Debug.WriteLine("Executing action: " + ActionOnLayout.Method.Name + " on layout: " + layout);
             ActionOnLayout();
         }
         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));
 }
Example #2
0
 /// <summary>
 /// Change lang display text.
 /// </summary>
 /// <param name="to">Text to be changed to.</param>
 public void ChangeLD(string to)
 {
     if (to == lastText)
     {
         return;
     }
     lbLang.Text = lastText = to;
     if (DisplayFlag)
     {
         lbLang.Visible = false;
         MahouUI.RefreshFLAG();
         if (MMain.mahou.MouseTTAlways && mouseDisplay)                 // fix for tray stuck due to variable "LayoutChanged" which being changed by this mouse tooltip always
         {
             MMain.mahou.icon.trIcon.Icon = Icon.FromHandle(MahouUI.FLAG.GetHicon());
         }
         BackgroundImage = MahouUI.FLAG;
         TransparencyKey = BackColor = Color.Pink;
         Invalidate();
         Update();
     }
     if (!transparentBG)
     {
         return;
     }
     Invalidate();
     Update();
 }
Example #3
0
 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") + "].");
         if (start_cyclEmuSwitch)
         {
             if (layout != cycleEmuDesiredLayout)
             {
                 KMHook.CycleEmulateLayoutSwitch();
             }
             else
             {
                 start_cyclEmuSwitch = false;
             }
         }
         else
         {
             MahouUI.RefreshFLAG();
             MMain.mahou.RefreshAllIcons();
             MMain.mahou.UpdateLDs();
         }
     }
     return(WinAPI.DefWindowProcW(hWnd, msg, wParam, lParam));
 }
Example #4
0
 protected override void WndProc(ref Message m)
 {
     if (m.Msg == jkluMSG)
     {
         uint layout = (uint)m.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 (MahouUI.MAIN_LAYOUT1 == layout || MahouUI.MAIN_LAYOUT2 == layout)
                 {
                     KMHook.last_switch_layout = layout;
                     KMHook.evt_layoutchanged(layout, 0, MahouUI.bindable_events[0]);
                 }
             }
         }
         if (!self_change && !start_cyclEmuSwitch)
         {
             MahouUI.RefreshFLAG();
             MMain.mahou.RefreshAllIcons();
             MMain.mahou.UpdateLDs();
             if (anull && !KMHook.selfie)
             {
                 KMHook.AS_IGN_fun();
             }
         }
     }
     base.WndProc(ref m);
 }
Example #5
0
 public LangPanel()
 {
     InitializeComponent();
     Height = 24;
     AeroCheck();
     MahouUI.DPISCALE(this);
     l = Convert.ToInt32(MahouUI.xr * l);
     outsidefix(pct_Flag);
     outsidefix(pct_Upper);
 }
Example #6
0
 public LangPanel()
 {
     InitializeComponent();
     this.FormClosing += (s, e) => { e.Cancel = true; this.Hide(); };
     Height            = 24;
     AeroCheck();
     MahouUI.DPISCALE(this);
     l = Convert.ToInt32(MahouUI.xr * l);
     outsidefix(pct_Flag);
     outsidefix(pct_Upper);
 }
Example #7
0
 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_fun();
             }
         }
     }
     return(WinAPI.DefWindowProcW(hWnd, msg, wParam, lParam));
 }
Example #8
0
        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();
        }
Example #9
0
 [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();
     }
 }
Example #10
0
        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));
        }
Example #11
0
 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));
 }
Example #12
0
 [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, GGPU_Mutex)) {
         if (!mutex.WaitOne(0, false))
         {
             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);
             }
             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.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();
         rif   = new RawInputForm();
         Locales.IfLessThan2();
         if (MyConfs.Read("Layouts", "MainLayout1") == "" && MyConfs.Read("Layouts", "MainLayout2") == "")
         {
             mahou.cbb_MainLayout1.SelectedIndex = 0;
             mahou.cbb_MainLayout2.SelectedIndex = 1;
         }
         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);
             }
         }
         MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetLocaleFromString(mahou.MainLayout1).uId;
         Application.Run();
     }
 }
Example #13
0
        [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();
                }
            }
        }