Last active
October 29, 2016 13:35
-
-
Save rubyu/6de4bf1c5f7d936bc2df2873173dec65 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using CreviceApp.WinAPI.Window; | |
using static CreviceApp.WinAPI.Constants.WindowsMessages; | |
using static CreviceApp.WinAPI.Constants.VirtualKeys; | |
class VerticalWheelManager | |
{ | |
public readonly int SuppressionDuration; | |
public readonly int ForceEmitThreshold; | |
public readonly VerticalWheel Up; | |
public readonly VerticalWheel Down; | |
public VerticalWheelManager(int duration, int threshold) | |
{ | |
this.SuppressionDuration = duration; | |
this.ForceEmitThreshold = threshold; | |
this.Up = new VerticalWheel(this); | |
this.Down = new VerticalWheel(this); | |
} | |
public class VerticalWheel | |
{ | |
private int count = 0; | |
private readonly System.Threading.Timer timer; | |
private readonly VerticalWheelManager manager; | |
public VerticalWheel(VerticalWheelManager manager) | |
{ | |
this.manager = manager; | |
this.timer = new System.Threading.Timer(new System.Threading.TimerCallback( delegate { Reset(); } )); | |
} | |
private VerticalWheel GetCounterpart() | |
{ | |
return manager.Up == this ? manager.Down : manager.Up; | |
} | |
public bool Check() | |
{ | |
GetCounterpart().Reset(); | |
count += 1; | |
if (count == (manager.ForceEmitThreshold < 2 ? 1 : 2)) | |
{ | |
timer.Change(manager.SuppressionDuration, System.Threading.Timeout.Infinite); | |
return true; | |
} | |
if (count > manager.ForceEmitThreshold) | |
{ | |
Reset(); | |
return Check(); | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
public void Reset() | |
{ | |
count = 0; | |
timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); | |
} | |
} | |
} | |
/* | |
* Gesture definitions for standard browsers. | |
*/ | |
var Browser = @when((ctx) => | |
{ | |
return ctx.ForegroundWindow.ModuleName == "chrome.exe" || | |
ctx.ForegroundWindow.ModuleName == "firefox.exe" || | |
ctx.ForegroundWindow.ModuleName == "opera.exe" || | |
ctx.ForegroundWindow.ModuleName == "iexplore.exe" || | |
(ctx.ForegroundWindow.ModuleName == "explorer.exe" && | |
ctx.PointedWindow.ClassName == "DirectUIHWND"); | |
}); | |
var VWManagerForBrowser = new VerticalWheelManager( | |
400, // Duration in milliseconds for suppression of wheel events given after once it have emitted. | |
6 // Max number of the wheel events which will be suppressed in the duration for suppression. | |
); | |
Browser. | |
@on(RightButton). | |
@if(WheelUp). | |
@do((ctx) => | |
{ | |
if (VWManagerForBrowser.Up.Check()) | |
{ | |
SendInput.Multiple(). | |
ExtendedKeyDown(VK_CONTROL). | |
ExtendedKeyDown(VK_SHIFT). | |
ExtendedKeyDown(VK_TAB). | |
ExtendedKeyUp(VK_TAB). | |
ExtendedKeyUp(VK_SHIFT). | |
ExtendedKeyUp(VK_CONTROL). | |
Send(); // Previous tab | |
} | |
}); | |
Browser. | |
@on(RightButton). | |
@if(WheelDown). | |
@do((ctx) => | |
{ | |
if (VWManagerForBrowser.Down.Check()) | |
{ | |
SendInput.Multiple(). | |
ExtendedKeyDown(VK_CONTROL). | |
ExtendedKeyDown(VK_TAB). | |
ExtendedKeyUp(VK_TAB). | |
ExtendedKeyUp(VK_CONTROL). | |
Send(); // Next tab | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment