Create a gist now

Instantly share code, notes, and snippets.

@rubyu /ForM546.csx
Last active Oct 29, 2016

What would you like to do?
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