Rank: Member
Groups: Approved
Joined: 3/31/2024(UTC) Posts: 14
Thanks: 1 times Was thanked: 1 time(s) in 1 post(s)
|
If you have any ideas, comments, or suggestions, don't hesitate :) The clipboard returns to its original state (the state it was in before) each time after an action (search) is performed copy How it works: if text is selected, it will be copied; if the same text is copied again, it will scroll the page Depending on the distance of the gesture, you can scroll down a little or to the end of the page + It works in almost all applications where scrolling is available + If there are two columns on the page, they can be scrolled independently of each other
Code:
// Create a DisplayTextInfo object once
var info = new DisplayTextInfo();
info.MessageAlignment = 'top';
info.Duration = 300;
info.Opacity = 0.9;
info.MessageFont = new Font('Segoe UI Semibold', 20);
info.BackColor = 'black';
info.ForeColor = 'white';
info.Padding = 15;
info.FadeSteps = 18;
//info.UsePrimaryScreen = true;
function displayMessage(message) {
info.Message = message;
info.Location = `${action.End.X + 10},${action.End.Y + 10}`;
sp.DisplayText(info);
}
var clip1 = clip.GetText();
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]);
sp.Sleep(100);
// Check if clipboard content changed after copying
if (clip1 != clip.GetText()) {
displayMessage('Copy');
} else {
var distance = parseInt(Math.sqrt(Math.pow((action.End.X - action.Start.X), 2.0) + Math.pow((action.End.Y - action.Start.Y), 2.0)));
var currentMousePosition = sp.GetCurrentMousePoint();
// Check if the foreground window is a browser
var fgWnd = sp.ForegroundWindow();
var exeName = fgWnd.Process.MainModule.ModuleName.toLowerCase();
var isBrowser = exeName.includes("chrome") || exeName.includes("firefox") || exeName.includes("msedge");
if (distance < 120) {
sp.MouseWheel(currentMousePosition, false, -260);
displayMessage('<120');
} else if (distance < 220) {
sp.MouseWheel(currentMousePosition, false, -400);
displayMessage('<220');
} else {
if (isBrowser) {
displayMessage('Alt Down');
var scrollAmount = -1900;
var scrollDelay = 1;
var scrollCount = 600;
var wParam = (scrollAmount << 16) | 0x0000;
var lParam = (currentMousePosition.Y << 16) | currentMousePosition.X;
var control = sp.WindowFromPoint(currentMousePosition, true);
var stateBefore = captureScreenState();
var unchangedCount = 0;
for (var i = 0; i < scrollCount; i++) {
control.PostMessage(host.cast(uint, 0x020A), new IntPtr(wParam), new IntPtr(lParam));
sp.Sleep(scrollDelay);
if (i % 50 === 0) { // Check every 50 iterations
var stateAfter = captureScreenState();
if (compareScreenStates(stateBefore, stateAfter)) {
unchangedCount++;
if (unchangedCount >= 3) { // If screen hasn't changed for 3 checks, stop scrolling
//displayMessage('End of page');
break;
}
} else {
unchangedCount = 0;
}
stateBefore = stateAfter;
}
}
} else {
// For non-browsers, use the original logic
var stateBefore = captureScreenState();
sp.SendModifiedVKeys([vk.LCONTROL], [vk.END]);
sp.Sleep(100);
var stateAfter = captureScreenState();
if (compareScreenStates(stateBefore, stateAfter)) {
displayMessage('Alt Down');
var scrollAmount = -1900;
var scrollDelay = 1;
var scrollCount = 1300;
var wParam = (scrollAmount << 16) | 0x0000;
var lParam = (currentMousePosition.Y << 16) | currentMousePosition.X;
var control = sp.WindowFromPoint(currentMousePosition, true);
for (var i = 0; i < scrollCount; i++) {
control.PostMessage(host.cast(uint, 0x020A), new IntPtr(wParam), new IntPtr(lParam));
sp.Sleep(scrollDelay);
}
} else {
displayMessage('Down');
}
}
}
}
// Function to capture screen state
function captureScreenState() {
var screen = System.Windows.Forms.Screen.PrimaryScreen;
var screenWidth = screen.Bounds.Width;
var screenHeight = screen.Bounds.Height;
var state = [];
// Create a bitmap of the entire screen
var bmp = new System.Drawing.Bitmap(screenWidth, screenHeight);
var g = System.Drawing.Graphics.FromImage(bmp);
g.CopyFromScreen(0, 0, 0, 0, new System.Drawing.Size(screenWidth, screenHeight));
// Define the left half region
var leftHalfWidth = screenWidth * 0.5; // Half of the screen width
var leftHalfHeight = screenHeight;
var leftHalfLeft = 0;
var leftHalfTop = 0;
// Capture pixels from the left half region
var numLeftHalfSamples = 15; // Adjust the number of samples for the left half region as needed
for (var i = 0; i < numLeftHalfSamples; i++) {
for (var j = 0; j < numLeftHalfSamples; j++) {
var pixelX = Math.floor(leftHalfLeft + leftHalfWidth * (i + 1) / (numLeftHalfSamples + 1));
var pixelY = Math.floor(leftHalfTop + leftHalfHeight * (j + 1) / (numLeftHalfSamples + 1));
state.push(bmp.GetPixel(pixelX, pixelY));
}
}
// Clean up
g.Dispose();
bmp.Dispose();
return state;
}
// Function to compare screen states
function compareScreenStates(state1, state2, tolerance = 20) {
if (state1.length !== state2.length) {
return false;
}
var unchangedPixels = 0;
for (var i = 0; i < state1.length; i++) {
var diff = Math.abs(state1[i].R - state2[i].R) +
Math.abs(state1[i].G - state2[i].G) +
Math.abs(state1[i].B - state2[i].B);
if (diff <= tolerance) {
unchangedPixels++;
}
}
// If more than 90% of the pixels remained unchanged, consider it as no scroll
return (unchangedPixels / state1.length) > 0.9;
}
paste There are only two states: paste or scroll the page to the top
Code:
// Create a DisplayTextInfo object once
var info = new DisplayTextInfo();
info.MessageAlignment = 'top';
info.Duration = 300;
info.Opacity = 0.9;
info.MessageFont = new Font('Segoe UI Semibold', 20);
info.BackColor = 'black';
info.ForeColor = 'white';
info.Padding = 15;
info.FadeSteps = 18;
//info.UsePrimaryScreen = true;
function displayMessage(message) {
info.Message = message;
info.Location = `${action.End.X + 10},${action.End.Y + 10}`;
sp.DisplayText(info);
}
var distance = parseInt(Math.sqrt(Math.pow((action.End.X - action.Start.X), 2.0) + Math.pow((action.End.Y - action.Start.Y), 2.0)));
// Check if the foreground window is a browser
var fgWnd = sp.ForegroundWindow();
var exeName = fgWnd.Process.MainModule.ModuleName.toLowerCase();
var isBrowser = exeName.includes("chrome") || exeName.includes("firefox") || exeName.includes("msedge");
if (distance < 220) {
// If distance is less than 220, paste text
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_V]);
displayMessage('Paste');
} else {
// If distance is 220 or more
if (isBrowser) {
// For browsers, always use alt scroll
displayMessage('Alt Up');
var currentMousePosition = sp.GetCurrentMousePoint();
var scrollAmount = 1900; // Positive for scrolling up
var scrollDelay = 1;
var scrollCount = 1300;
var wParam = (scrollAmount << 16) | 0x0000;
var lParam = (currentMousePosition.Y << 16) | currentMousePosition.X;
var control = sp.WindowFromPoint(currentMousePosition, true);
var stateBefore = captureScreenState();
var unchangedCount = 0;
for (var i = 0; i < scrollCount; i++) {
control.PostMessage(0x020A, new IntPtr(wParam), new IntPtr(lParam));
sp.Sleep(scrollDelay);
if (i % 50 === 0) { // Check every 50 iterations
var stateAfter = captureScreenState();
if (compareScreenStates(stateBefore, stateAfter)) {
unchangedCount++;
if (unchangedCount >= 3) { // If screen hasn't changed for 3 checks, stop scrolling
break;
}
} else {
unchangedCount = 0;
}
stateBefore = stateAfter;
}
}
} else {
// For non-browsers, use the original logic
var stateBefore = captureScreenState();
sp.SendModifiedVKeys([vk.LCONTROL], [vk.HOME]);
sp.Sleep(100); // Give some time for the action to take effect
var stateAfter = captureScreenState();
if (compareScreenStates(stateBefore, stateAfter)) {
// If screen states are almost the same, Ctrl+Home didn't work
// Use alternative method
displayMessage('Alt Up');
var currentMousePosition = sp.GetCurrentMousePoint();
var scrollAmount = 1900; // Positive for scrolling up
var scrollDelay = 1;
var scrollCount = 1300;
var wParam = (scrollAmount << 16) | 0x0000;
var lParam = (currentMousePosition.Y << 16) | currentMousePosition.X;
var control = sp.WindowFromPoint(currentMousePosition, true);
var stateBefore = captureScreenState();
var unchangedCount = 0;
for (var i = 0; i < scrollCount; i++) {
control.PostMessage(0x020A, new IntPtr(wParam), new IntPtr(lParam));
sp.Sleep(scrollDelay);
if (i % 50 === 0) { // Check every 50 iterations
var stateAfter = captureScreenState();
if (compareScreenStates(stateBefore, stateAfter)) {
unchangedCount++;
if (unchangedCount >= 3) { // If screen hasn't changed for 3 checks, stop scrolling
break;
}
} else {
unchangedCount = 0;
}
stateBefore = stateAfter;
}
}
} else {
// If screen states changed significantly, Ctrl+Home worked
displayMessage('UP');
}
}
}
// Function to capture screen state
function captureScreenState() {
var screen = System.Windows.Forms.Screen.PrimaryScreen;
var screenWidth = screen.Bounds.Width;
var screenHeight = screen.Bounds.Height;
var state = [];
// Create a bitmap of the entire screen
var bmp = new System.Drawing.Bitmap(screenWidth, screenHeight);
var g = System.Drawing.Graphics.FromImage(bmp);
g.CopyFromScreen(0, 0, 0, 0, new System.Drawing.Size(screenWidth, screenHeight));
// Define the left half region
var leftHalfWidth = screenWidth * 0.5; // Half of the screen width
var leftHalfHeight = screenHeight;
var leftHalfLeft = 0;
var leftHalfTop = 0;
// Capture pixels from the left half region
var numLeftHalfSamples = 15; // Adjust the number of samples for the left half region as needed
for (var i = 0; i < numLeftHalfSamples; i++) {
for (var j = 0; j < numLeftHalfSamples; j++) {
var pixelX = Math.floor(leftHalfLeft + leftHalfWidth * (i + 1) / (numLeftHalfSamples + 1));
var pixelY = Math.floor(leftHalfTop + leftHalfHeight * (j + 1) / (numLeftHalfSamples + 1));
state.push(bmp.GetPixel(pixelX, pixelY));
}
}
// Clean up
g.Dispose();
bmp.Dispose();
return state;
}
// Function to compare screen states
function compareScreenStates(state1, state2, tolerance = 20) {
if (state1.length !== state2.length) {
return false;
}
var unchangedPixels = 0;
for (var i = 0; i < state1.length; i++) {
var diff = Math.abs(state1[i].R - state2[i].R) +
Math.abs(state1[i].G - state2[i].G) +
Math.abs(state1[i].B - state2[i].B);
if (diff <= tolerance) {
unchangedPixels++;
}
}
// If more than 90% of the pixels remained unchanged, consider it as no scroll
return (unchangedPixels / state1.length) > 0.9;
}
forward when starting the gesture from a link: the link opens in a new tab; when starting the gesture not from a link and there is selected text on the page: a new tab opens with a search for the selected text, depending on the length of the gesture; when starting the gesture not from a link and there is no selected text on the page: the "Forward" action is performed in the browser; +It also works in any application: the browser opens and searches
Code:
// - when starting the gesture from a link: the link opens in a new tab;
// - when starting the gesture not from a link and there is selected text on the page: a new tab opens with a search for the selected text, depending on the length of the gesture;
// - when starting the gesture not from a link and there is no selected text on the page: the "Forward" action is performed in the browser;
//var stopwatch = new System.Diagnostics.Stopwatch();
//stopwatch.Start();
var info = new DisplayTextInfo();
info.MessageAlignment = 'center';
info.Duration = 500;
info.Opacity = 0.9;
info.MessageFont = new Font('Segoe UI Semibold', 20);
info.BackColor = 'black';
info.ForeColor = 'white';
info.Padding = 15;
info.FadeSteps = 18;
//info.UsePrimaryScreen = true;
var screen = System.Windows.Forms.Screen.PrimaryScreen;
// Approximate estimation of message width and height
var messageWidth = 300; // Estimated message width
var messageHeight = 100; // Estimated message height
// Calculate position for centering
var centerX = (screen.Bounds.Width - messageWidth) / 2;
var centerY = (screen.Bounds.Height - messageHeight) / 2;
info.Location = `${centerX},${centerY}`;
sp.MouseMove(action.Start);
sp.Sleep(10);
var currentMouseCursor = sp.GetCurrentMouseCursor();
var distance = parseInt(Math.sqrt(Math.pow((action.End.X - action.Start.X), 2.0) + Math.pow((action.End.Y - action.Start.Y), 2.0)));
var fgWnd = sp.ForegroundWindow();
var exeName = fgWnd.Process.MainModule.ModuleName.toLowerCase();
var isBrowser = exeName.includes("chrome") || exeName.includes("firefox") || exeName.includes("msedge");
var forwardExecuted = false;
if (currentMouseCursor != 'Hand') {
var originalTitle = fgWnd.Title;
sp.SendVKey(vk.BROWSER_FORWARD);
sp.Sleep(10);
var newTitle = sp.ForegroundWindow().Title;
if (newTitle !== originalTitle) {
info.Message = 'Forward';
forwardExecuted = true;
}
}
if (!forwardExecuted) {
if (currentMouseCursor == 'Hand') {
sp.MouseClick(action.Start, MouseButtons.Middle, true, true);
sp.MouseMove(action.End);
info.Message = 'Link: New Tab';
} else {
sp.MouseMove(action.End);
var originalClipboardContent = clip.GetText() || '';
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]);
sp.Sleep(100);
var newClipboardContent = clip.GetText() || '';
if (newClipboardContent !== originalClipboardContent) {
var searchText = newClipboardContent.trim();
if (searchText !== '') {
var searchPrefix = '';
if (distance < 160) {
info.Message = '<160 Standard Search';
} else if (distance < 320) {
searchPrefix = 'https://www.google.com/search?tbm=isch&q=';
info.Message = '<320 Google Image Search';
} else {
searchPrefix = 'https://www.youtube.com/results?search_query=';
info.Message = '>320 YouTube Search';
}
if (isBrowser) {
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_T]);
sp.Sleep(110);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_L]);
sp.Sleep(100);
clip.SetText(searchPrefix + searchText);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_V]);
sp.Sleep(70);
sp.SendVKey(vk.RETURN);
} else {
var fullUrl = (searchPrefix || 'https://www.google.com/search?q=') + encodeURIComponent(searchText);
sp.RunProgram(fullUrl, '', 'open', 'normal', true, false, false);
}
}
if (originalClipboardContent) {
clip.SetText(originalClipboardContent);
} else {
clip.Clear();
}
} else {
info.Message = 'No text selected';
}
}
}
//stopwatch.Stop();
//var elapsedTime = stopwatch.ElapsedMilliseconds;
//info.Message += `\nTime: ${elapsedTime}ms`;
sp.DisplayText(info);
//sp.ConsoleError(`Script execution time: ${elapsedTime}ms`, 'Performance', System.Drawing.Color.Red);
Max or Restore Everything is a program for fast file searching on your computer. If text is selected, it searches for it in Everything; if nothing is selected, the window is restored/maximized Replace with your path (keep in mind you need to use \\) sp.RunProgram('C:\\test\\Everything.exe'
Code:
var info = new DisplayTextInfo();
info.MessageAlignment = 'center'; // Text alignment: 'left', 'center', 'right'
info.Duration = 500; // Display duration in milliseconds
info.Opacity = 0.9; // Opacity: from 0.05 (almost transparent) to 1.0 (opaque)
info.MessageFont = new Font('Segoe UI Semibold', 20); // Font and text size
info.BackColor = 'black'; // Background color: can use color names or RGB
info.ForeColor = 'white'; // Text color: can use color names or RGB
info.Padding = 15; // Text padding from the edges of the message in pixels
info.FadeSteps = 18; // Number of steps for fade in/out effect
//info.UsePrimaryScreen = true;
var screen = System.Windows.Forms.Screen.PrimaryScreen;
// Approximate estimation of message width and height
var messageWidth = 300; // Estimated message width
var messageHeight = 100; // Estimated message height
// Calculate position for centering
var centerX = (screen.Bounds.Width - messageWidth) / 2;
var centerY = (screen.Bounds.Height - messageHeight) / 2;
info.Location = `${centerX},${centerY}`;
// The rest of the code remains unchanged
var distance = parseInt(Math.sqrt(Math.pow((action.End.X - action.Start.X), 2.0) + Math.pow((action.End.Y - action.Start.Y), 2.0)));
var originalClipboardContent = clip.GetText();
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]);
sp.Sleep(100);
var newClipboardContent = clip.GetText();
if (newClipboardContent !== originalClipboardContent) {
var searchText = newClipboardContent.trim().replace(/"/g, '');
if (searchText !== '') {
if (distance < 250) {
var escapedSearchText = searchText.replace(/\\/g, '\\\\');
sp.RunProgram('C:\\test\\Everything.exe', '-search "' + escapedSearchText + '"', '', '', true, false, false);
info.Message = '<250 Search in Everything';
} else if (distance < 370) {
sp.SendVKey(vk.LWIN);
sp.Sleep(100);
sp.SendKeys(searchText);
info.Message = '<370 Windows Search';
}
}
if (originalClipboardContent) {
clip.SetText(originalClipboardContent);
} else {
clip.Clear();
}
} else {
if (action.Window.Maximized) {
action.Window.Restore();
info.Message = 'Window restored';
} else {
action.Window.Maximize();
info.Message = 'Window maximized';
}
}
sp.Sleep(200);
sp.DisplayText(info);
search on the page-in any application The first gesture searches, a longer gesture finds the next match, an even longer gesture finds the previous match
Code:
// Create a DisplayTextInfo object once
var info = new DisplayTextInfo();
info.MessageAlignment = 'center'; // Text alignment: 'left', 'center', 'right'
info.Duration = 500; // Display duration in milliseconds
info.Opacity = 0.9; // Opacity: from 0.05 (almost transparent) to 1.0 (opaque)
info.MessageFont = new Font('Segoe UI Semibold', 20); // Font and text size
info.BackColor = 'black'; // Background color: can use color names or RGB
info.ForeColor = 'white'; // Text color: can use color names or RGB
info.Padding = 15; // Text padding from the edges of the message in pixels
info.FadeSteps = 18; // Number of steps for fade in/out effect
//info.UsePrimaryScreen = true;
var screen = System.Windows.Forms.Screen.PrimaryScreen;
// Approximate estimation of message width and height
var messageWidth = 300; // Estimated message width
var messageHeight = 100; // Estimated message height
// Calculate position for centering
var centerX = (screen.Bounds.Width - messageWidth) / 2;
var centerY = (screen.Bounds.Height - messageHeight) / 2;
info.Location = `${centerX},${centerY}`;
var distance = parseInt(Math.sqrt(Math.pow((action.End.X - action.Start.X), 2.0) + Math.pow((action.End.Y - action.Start.Y), 2.0)));
// Check if the foreground window is a browser
var fgWnd = sp.ForegroundWindow();
var exeName = fgWnd.Process.MainModule.ModuleName.toLowerCase();
var isBrowser = exeName.includes("chrome") || exeName.includes("firefox") || exeName.includes("msedge");
var isExplorer = exeName.includes("explorer");
var isDiscord = exeName.includes("discord");
if (distance < 160) {
var originalClipboardContent = clip.GetText();
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]);
sp.Sleep(100);
var newClipboardContent = clip.GetText();
if (newClipboardContent !== originalClipboardContent) {
if (isExplorer) {
// For Explorer, first exit rename mode (if active)
sp.SendVKey(vk.ESCAPE);
sp.Sleep(100);
}
if (isDiscord) {
// For Discord, open search, paste and press Enter
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_F]);
sp.Sleep(100);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_V]);
sp.Sleep(50);
sp.SendVKey(vk.RETURN);
info.Message = 'Discord: Search';
} else if (isBrowser) {
// For browsers, just Ctrl+F
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_F]);
info.Message = 'Browser: Search';
} else {
// Default action for other applications
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_F]);
sp.Sleep(100);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_V]);
info.Message = 'Search';
}
} else {
info.Message = ''; // Empty message if no text was copied
}
} else if (distance < 350) {
// Move to next match using F3
sp.SendVKey(vk.F3);
sp.Sleep(100);
info.Message = 'Next match';
} else {
// Move to previous match using Shift+F3
sp.SendModifiedVKeys([vk.SHIFT], [vk.F3]);
sp.Sleep(100);
info.Message = 'Previous match';
}
sp.DisplayText(info);
|