forked from gmamaladze/globalmousekeyhook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f97055
commit 547e453
Showing
11 changed files
with
179 additions
and
79 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Windows.Forms; | ||
using Gma.System.MouseKeyHook; | ||
|
||
namespace ConsoleHook | ||
{ | ||
internal class DetectCombinations | ||
{ | ||
public static void Do(AutoResetEvent quit) | ||
{ | ||
var map = new Dictionary<Combination, Action> | ||
{ | ||
//Specify which key combinations to detect and action - what to do if detected. | ||
//You can create a key combinations directly from string or ... | ||
{Combination.FromString("A+B+C") , () => Console.WriteLine(":-)")}, | ||
//... or alternatively you can use builder methods | ||
{Combination.TriggeredBy(Keys.F).With(Keys.E).With(Keys.D) , () => Console.WriteLine(":-D")}, | ||
{Combination.FromString("Alt+A") , () => Console.WriteLine(":-P")}, | ||
{Combination.FromString("Control+Shift+Z") , () => Console.WriteLine(":-/")}, | ||
{Combination.FromString("Escape") , () => quit.Set()}, | ||
}; | ||
|
||
Console.WriteLine("Detecting following combinations:"); | ||
foreach (var combination in map.Keys) | ||
{ | ||
Console.WriteLine("\t{0}",combination); | ||
} | ||
Console.WriteLine("Press ESC to exit."); | ||
|
||
//Actual loop | ||
Hook.GlobalEvents().OnCombination(map); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using Gma.System.MouseKeyHook; | ||
|
||
namespace ConsoleHook | ||
{ | ||
internal class DetectSequences | ||
{ | ||
public static void Do(AutoResetEvent quit) | ||
{ | ||
var map = new Dictionary<Sequence, Action> | ||
{ | ||
{Sequence.FromString("Control+Z,B") , Console.WriteLine}, | ||
{Sequence.FromString("Control+Z,Z") , Console.WriteLine}, | ||
{Sequence.FromString("Escape,Escape,Escape") , () => quit.Set()}, | ||
}; | ||
|
||
Console.WriteLine("Detecting following combinations:"); | ||
foreach (var sequence in map.Keys) | ||
{ | ||
Console.WriteLine("\t{0}", sequence); | ||
} | ||
Console.WriteLine("Press 3 x ESC (three times) to exit."); | ||
|
||
//Actual loop | ||
Hook.GlobalEvents().OnSequence(map); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Threading; | ||
using Gma.System.MouseKeyHook; | ||
|
||
internal class LogKeys | ||
{ | ||
public static void Do(AutoResetEvent quit) | ||
{ | ||
Hook.GlobalEvents().KeyPress += (sender, e) => | ||
{ | ||
Console.Write(e.KeyChar); | ||
if (e.KeyChar == 'q') quit.Set(); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using Gma.System.MouseKeyHook; | ||
|
||
namespace ConsoleHook | ||
{ | ||
class QuickStart | ||
{ | ||
public void Do() | ||
{ | ||
//1. Define key combinations | ||
var undo = Combination.FromString("Control+Z"); | ||
//Using builder method | ||
var undo2 = Combination.TriggeredBy(Keys.Z).With(Keys.Control); | ||
var fullScreen = Combination.FromString("Shift+Alt+Enter"); | ||
|
||
//2. Define actions | ||
Action actionUndo = DoSomething; | ||
Action actionFullScreen = () => { Console.WriteLine("You Pressed FULL SCREEN"); }; | ||
|
||
void DoSomething() | ||
{ | ||
Console.WriteLine("You pressed UNDO"); | ||
} | ||
|
||
//3. Assign actions to key combinations | ||
var assignment = new Dictionary<Combination, Action> | ||
{ | ||
{undo, actionUndo}, | ||
{fullScreen, actionFullScreen} | ||
}; | ||
|
||
//4. Install listener | ||
Hook.GlobalEvents().OnCombination(assignment); | ||
} | ||
|
||
public void DoCompact() | ||
{ | ||
void DoSomething() | ||
{ | ||
Console.WriteLine("You pressed UNDO"); | ||
} | ||
|
||
Hook.GlobalEvents().OnCombination(new Dictionary<Combination, Action> | ||
{ | ||
{Combination.FromString("Control+Z"), DoSomething}, | ||
{Combination.FromString("Shift+Alt+Enter"), () => { Console.WriteLine("You Pressed FULL SCREEN"); }} | ||
}); | ||
} | ||
|
||
public void DoSequence() | ||
{ | ||
var exitVim = Sequence.FromString("Shift+Z,Z"); | ||
var rename = Sequence.FromString("Control+R,R"); | ||
var exitReally = Sequence.FromString("Escape,Escape,Escape"); | ||
|
||
var assignment = new Dictionary<Sequence, Action> | ||
{ | ||
{exitVim, ()=>Console.WriteLine("No!")}, | ||
{rename, ()=>Console.WriteLine("rename2")}, | ||
{exitReally, ()=>Console.WriteLine("Ok.")}, | ||
}; | ||
|
||
Hook.GlobalEvents().OnSequence(assignment); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#Detecting Key Combinations and Seuqnces | ||
|
||
##Quickstart | ||
|
||
Assuming your goal is to detect whenever some key combination, shortcut is pressed and perform some action as a response. Use class `Combination` to describe key combinations. | ||
```csharp | ||
var undo = Combination.FromString("Control+Z"); | ||
var fullScreen = Combination.FromString("Shit+Alt+Enter"); | ||
``` | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.