summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatthewsotoudeh <matthewsot@outlook.com>2014-12-03 20:11:26 -0800
committermatthewsotoudeh <matthewsot@outlook.com>2014-12-03 20:11:26 -0800
commitb0a4b5406d17183e5ec845d5f47436ccaaf92961 (patch)
treeff7ed90f22bb73ac831aecee3cf7dcf42f09fd56
parent5f89b8159c625fed3103dea38d6792889e9a19b2 (diff)
intercepts volume controls
-rw-r--r--AntiVol/AntiVol/Form1.cs16
-rw-r--r--AntiVol/AntiVol/Keyboard.cs57
2 files changed, 21 insertions, 52 deletions
diff --git a/AntiVol/AntiVol/Form1.cs b/AntiVol/AntiVol/Form1.cs
index 9db4c1b..b440f03 100644
--- a/AntiVol/AntiVol/Form1.cs
+++ b/AntiVol/AntiVol/Form1.cs
@@ -7,6 +7,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using System.Runtime.InteropServices;
+//http://www.geekpedia.com/tutorial176_Get-and-set-the-wave-sound-volume.html
namespace AntiVol
{
@@ -18,12 +20,20 @@ namespace AntiVol
Program.hook.KeyIntercepted += Hook_KeyIntercepted;
}
- private void Hook_KeyIntercepted(KeyboardHook.KeyboardHookEventArgs e)
+ private bool Hook_KeyIntercepted(KeyboardHook.KeyboardHookEventArgs e)
{
- if (e.KeyName.Contains("VolumeUp"))
+ if (!e.KeyName.Contains("Volume")) return true;
+
+ switch (e.KeyName)
{
- //move up the volume
+ case "VolumeUp":
+ break;
+ case "VolumeDown":
+ break;
+ case "VolumeMute":
+ break;
}
+ return false;
}
private KeyboardHook hook;
diff --git a/AntiVol/AntiVol/Keyboard.cs b/AntiVol/AntiVol/Keyboard.cs
index 239982b..1a38372 100644
--- a/AntiVol/AntiVol/Keyboard.cs
+++ b/AntiVol/AntiVol/Keyboard.cs
@@ -200,57 +200,14 @@ public class KeyboardHook : IDisposable
private IntPtr HookCallback(
int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam)
{
- bool AllowKey = PassAllKeysToNextApp;
+ bool allowKey = true;
- //Filter wParam for KeyUp events only
if (nCode >= 0)
{
- if (wParam == (IntPtr)WM_KEYUP || wParam == (IntPtr)WM_SYSKEYUP)
- {
-
- // Check for modifier keys, but only if the key being
- // currently processed isn't a modifier key (in other
- // words, CheckModifiers will only run if Ctrl, Shift,
- // CapsLock or Alt are active at the same time as
- // another key)
- if (!(lParam.vkCode >= 160 && lParam.vkCode <= 164))
- {
- CheckModifiers();
- }
-
- // Check for key combinations that are allowed to
- // get through to Windows
- //
- // Ctrl+Esc or Windows key
- if (AllowWindowsKey)
- {
- switch (lParam.flags)
- {
- //Ctrl+Esc
- case 0:
- if (lParam.vkCode == 27)
- AllowKey = true;
- break;
-
- //Windows keys
- case 1:
- if ((lParam.vkCode == 91) || (lParam.vkCode == 92))
- AllowKey = true;
- break;
- }
- }
- // Alt+Tab
- if (AllowAltTab)
- {
- if ((lParam.flags == 32) && (lParam.vkCode == 9))
- AllowKey = true;
- }
-
- OnKeyIntercepted(new KeyboardHookEventArgs(lParam.vkCode, AllowKey));
- }
+ allowKey = OnKeyIntercepted(new KeyboardHookEventArgs(lParam.vkCode, allowKey));
//If this key is being suppressed, return a dummy value
- if (AllowKey == false)
+ if (allowKey == false)
return (System.IntPtr)1;
}
//Pass key to next application
@@ -264,17 +221,19 @@ public class KeyboardHook : IDisposable
/// Raises the KeyIntercepted event.
/// </summary>
/// <param name="e">An instance of KeyboardHookEventArgs</param>
- public void OnKeyIntercepted(KeyboardHookEventArgs e)
+ public bool OnKeyIntercepted(KeyboardHookEventArgs e)
{
if (KeyIntercepted != null)
- KeyIntercepted(e);
+ return KeyIntercepted(e);
+
+ return true;
}
/// <summary>
/// Delegate for KeyboardHook event handling.
/// </summary>
/// <param name="e">An instance of InterceptKeysEventArgs.</param>
- public delegate void KeyboardHookEventHandler(KeyboardHookEventArgs e);
+ public delegate bool KeyboardHookEventHandler(KeyboardHookEventArgs e);
/// <summary>
/// Event arguments for the KeyboardHook class's KeyIntercepted event.
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback