Skip to content

Commit

Permalink
Merge pull request #14 from Superritchman/dev
Browse files Browse the repository at this point in the history
fixed bug with modifier-keys
  • Loading branch information
Superritchman committed Aug 4, 2015
2 parents a90b8cd + 93e9908 commit da303e3
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 33 deletions.
18 changes: 7 additions & 11 deletions MainForm.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
65 changes: 53 additions & 12 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -29,20 +27,28 @@ static class Program
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);
Application.Run(mForm);
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)
Expand All @@ -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;
}
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ Also there is an range-indicator. So you will see how far you can go, before run
<li>Right-Click on the time to exit PortalCounter
</ol>

## Color-legend
<ul>
<li>Grey: Just highlighting the window for easier dragging it around</li>
<li>Red-Orange: Chatmode activated, even if you hit the hotkey(s), the countdown won't start or pause.<br>
Press 'Enter' to enter/leave the chatmode. (can be disabled in settings).</li>

## Changes
<ul>
<li><b>added chat-protection (hotkey don't trigger if you open the chat with 'Enter'))</b></li>
<li><b>fixed bug with modifier-keys</b></li>
<li>added chat-protection (hotkey don't trigger if you open the chat with 'Enter'))</li>
<li>fixed bug where the range wasn't calculated</li>
<li>Added modifier-key support (alt, shift, ctrl)</li>
<li>Updated descriptions to match with the latest trait-patch</li>
Expand Down
8 changes: 1 addition & 7 deletions SettingsForm.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Globalization;

namespace PortalCounter
{
Expand Down

0 comments on commit da303e3

Please sign in to comment.