Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
Create a hotkey, can use a single key - I used key "Z" for this example, see the end of the script to change as needed. I selected "Unregistered" and "Consume" so the key stroke isn't received by the application. I set this to only process for a certain executable (a local program I have with a numeric up/down), you will need to change for your program. Code://Only for this specific application, change as needed CASE-SENSITIVE!
if(sp.ForegroundWindow().Process.MainModule.ModuleName == "AllThumbs.exe")
{
//If the hotkey wasn't already pressed, start the process
if(!sp.GetStoredBool("ValueChangeActive"))
{
sp.StoreBool("ValueChangeActive", true);
//Save the starting mouse location to move it back later
sp.StorePoint("ValueChangeStartMouseLocation", sp.GetCurrentMousePoint());
//Change the location below as needed
var clickPoint = new Point(1840, 150);
//Move the mouse to the click location
sp.ConsumePhysicalInput(true);
sp.MouseMove(clickPoint);
sp.MouseClick(clickPoint, MouseButtons.Left, true, true);
sp.ConsumePhysicalInput(false);
sp.StorePoint("ValueChangeLastPoint", clickPoint);
//Create timer which checks every 100 milliseconds and compare the mouse up/down
//distance, change minimumDistance value as needed
sp.CreateTimer("ValueChange", 0, 100, `
if(!sp.GetStoredBool("ValueChangeTimerProcessing"))
{
sp.StoreBool("ValueChangeTimerProcessing", true);
//Change value below as needed, larger means mouse must
//move more to trigger next up/down
var minimumDistance = 10;
var lastMousePoint = sp.GetStoredPoint("ValueChangeLastPoint");
var currentMousePoint = sp.GetCurrentMousePoint();
if(currentMousePoint.Y >= lastMousePoint.Y + minimumDistance)
{
sp.SendVKey(vk.DOWN);
sp.StorePoint("ValueChangeLastPoint", currentMousePoint);
}
else if(currentMousePoint.Y <= lastMousePoint.Y - minimumDistance)
{
sp.SendVKey(vk.UP);
sp.StorePoint("ValueChangeLastPoint", currentMousePoint);
}
sp.StoreBool("ValueChangeTimerProcessing", false);
}
`);
}
else
{
//Second time hotkey is pressed, stop the process and move the mouse back
sp.DeleteStoredBool("ValueChangeActive");
sp.DeleteTimer("ValueChange");
sp.ConsumePhysicalInput(true);
sp.MouseMove(sp.GetStoredPoint("ValueChangeStartMouseLocation"));
sp.ConsumePhysicalInput(false);
}
}
else
{
//Since we consume Z, we need to send it for other apps
sp.SendVKey(vk.VK_Z);
}
|