StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
eugenes  
#1 Posted : Wednesday, February 17, 2021 8:09:15 AM(UTC)
eugenes

Rank: Member

Reputation:

Groups: Approved
Joined: 12/2/2019(UTC)
Posts: 20

Thanks: 2 times
Hi

How do I set up a hotkey that would execute only when the mouse pointer is inside a particular area (right side of the screen)?

Rob  
#2 Posted : Wednesday, February 17, 2021 2:58:27 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
This works okay for me.
Code:
// Get the location of the mouse cursor
var mouseLoc = sp.GetCurrentMousePoint();

// Get the rectangle of the screen where mouse is located
var mouseScreenRect = Screen.FromPoint(mouseLoc).Bounds;

// Divide the width of the screen in half and add the result to the Left starting location of the screen
// to define the center of the screen. parseInt ensures only whole numbers are used
var screenCenter = parseInt(mouseScreenRect.Left + (mouseScreenRect.Width / 2));

// If the mouse's X location is at or to the right of the screen's center, then show message
if(mouseLoc.X >= screenCenter) {
    sp.MessageBox("Right Side of screen", "Hotkey");
}

Edited by user Wednesday, February 17, 2021 2:59:45 PM(UTC)  | Reason: Not specified

Rob  
#3 Posted : Wednesday, February 17, 2021 3:06:55 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Another method using regions. This would be easier to work with if you wanted to divide the screen into a grid and do different things in different cells.

This example only creates a 1 Row, 2 Column region - but you could do 3 x 3 for example
Code:
// Get location of mouse cursor
var mouseLoc = sp.GetCurrentMousePoint();

// Get region the mouse cursor is in, based on the screen rectangle, 
// using 2 columns and 1 row to split the screen rectangle into
var columns = 2;
var rows = 1;
var region = sp.GetRegionFromPoint(Screen.FromPoint(mouseLoc).Bounds, mouseLoc, columns, rows); 

// If mouse is in Column 2 (right half) and Row 1 (only 1 row possible, but to demonstrate)
// Show message
if(region.Column === 2 && region.Row === 1) {
    sp.MessageBox("Right Side of screen", "Hotkey");
}

Edited by user Wednesday, February 17, 2021 3:20:05 PM(UTC)  | Reason: Not specified

eugenes  
#4 Posted : Wednesday, February 17, 2021 8:22:12 PM(UTC)
eugenes

Rank: Member

Reputation:

Groups: Approved
Joined: 12/2/2019(UTC)
Posts: 20

Thanks: 2 times
Works perfectly, thank you!
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.