diff --git a/MainForm.cs b/MainForm.cs index 4b07ba4..adfae93 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; +using Gw2Mem; +using System; using System.Drawing; -using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; -using System.Diagnostics; -using System.Runtime.InteropServices; -using Gw2Mem; - namespace PortalCounter { public partial class MainForm : Form @@ -167,12 +161,14 @@ private void MainForm_MouseUp(object sender, MouseEventArgs e) private void MainForm_Activated(object sender, EventArgs e) { - this.BackColor = Color.LightGray; + if(this.BackColor == Color.Black) + this.BackColor = Color.LightGray; } private void MainForm_Deactivate(object sender, EventArgs e) { - this.BackColor = Color.Black; + if(this.BackColor == Color.LightGray) + this.BackColor = Color.Black; this.BringToFront(); } diff --git a/Program.cs b/Program.cs index 0c05459..8b5d098 100644 --- a/Program.cs +++ b/Program.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Windows.Forms; using System.Diagnostics; using System.Runtime.InteropServices; +using System.Windows.Forms; namespace PortalCounter { @@ -29,13 +27,16 @@ private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, private static LowLevelKeyboardProc _proc = HookCallback; private static IntPtr _hookID = IntPtr.Zero; private static bool chatactive = false; + private static System.Timers.Timer aTimer = new System.Timers.Timer(1000); + private static bool preventSpam = false; private static MainForm mForm = new MainForm(); - public static Boolean hook = true; + public static bool hook = true; [STAThread] static void Main() { + aTimer.Elapsed += aTimer_Elapsed; _hookID = SetHook(_proc); Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); @@ -43,6 +44,11 @@ static void Main() UnhookWindowsHookEx(_hookID); } + private static void aTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + preventSpam = false; + } + private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); private static IntPtr SetHook(LowLevelKeyboardProc proc) @@ -55,24 +61,59 @@ private static IntPtr SetHook(LowLevelKeyboardProc proc) } private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) - { - if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) + { + if (hook && nCode >= 0 && (wParam == (IntPtr)WM_KEYDOWN || Control.ModifierKeys != Keys.None)) { Keys vkCode = (Keys)Marshal.ReadInt32(lParam); + + // read settings + bool bChat = Properties.Settings.Default.ProtectChat; + Keys kHotKey = PortalCounter.Properties.Settings.Default.HotKey; + Keys kModifier = Properties.Settings.Default.Modifier; - if (hook && Properties.Settings.Default.ProtectChat && vkCode == Keys.Enter && PortalCounter.Properties.Settings.Default.HotKey != Keys.Enter) - { + // deactivate chat only if hotkey isnt enter + if (bChat && vkCode == Keys.Enter && kHotKey != Keys.Enter) chatactive = !chatactive; - mForm.BackColor = chatactive ? System.Drawing.Color.OrangeRed : System.Drawing.Color.Black; - } - if (!chatactive && hook && vkCode.Equals(PortalCounter.Properties.Settings.Default.HotKey) && Control.ModifierKeys == Properties.Settings.Default.Modifier) + if (!chatactive) + { + mForm.BackColor = System.Drawing.Color.Black; + + Console.WriteLine(kHotKey + " - " + Control.ModifierKeys); + + kHotKey = normalizeHotkey(kHotKey); + + // (Hotkey and modifier) or (hokey is actual modifier) + if (!preventSpam && (vkCode.Equals(kHotKey) && Control.ModifierKeys == kModifier) || Control.ModifierKeys.Equals(kHotKey)) + { + mForm.startTimer(); + + if (!kModifier.Equals(Keys.None)) + { + preventSpam = true; + aTimer.Start(); + } + } + } + else { - mForm.startTimer(); + mForm.BackColor = System.Drawing.Color.OrangeRed; } } return CallNextHookEx(_hookID, nCode, wParam, lParam); } + + private static Keys normalizeHotkey(Keys input) + { + if (input.Equals(Keys.ControlKey)) + return Keys.Control; + if (input.Equals(Keys.Menu)) + return Keys.Alt; + if(input.Equals(Keys.ShiftKey)) + return Keys.Shift; + + return input; + } } } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index bf76f10..6bebe7b 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -33,6 +33,6 @@ // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.0.0")] -[assembly: AssemblyFileVersion("1.3.0.0")] +[assembly: AssemblyVersion("1.3.1.0")] +[assembly: AssemblyFileVersion("1.3.1.0")] [assembly: NeutralResourcesLanguageAttribute("en")] diff --git a/README.md b/README.md index 04bbf3b..83c1463 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,16 @@ Also there is an range-indicator. So you will see how far you can go, before run
  • Right-Click on the time to exit PortalCounter +## Color-legend +