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)
|
So that's actually a little trickier than it seems it should be. Ultimately, the application controls focus, meaning that for a generic and consistently functional means of handling things, the mouse simply needs to be clicked somewhere that causes the application to change focus; or perform an equivalent keyboard command that takes focus away from a text field. The problem is defining those events, especially across different applications. The first two scripts below simply click 1 pixel in and up from the lower left corner of the window and move the mouse back. I tested this in Notepad++ and Firefox and it seemed to work fine. However, since Firefox doesn't have have a visible border/status bar area, it's possible that depending on the web page, this could result in clicking on something within the page. The last script only works for Firefox, but it sends Ctrl+L to change focus to the address bar, then sends Tab twice, which on my computer (no extensions, default toolbar) returns focus to the web page area, then sends Ctrl+End. It seems like this should be much simpler than it actually is, but at the end of the day, StrokesPlus.net can only interact with an application externally; any logic for controlling field focus is entirely dictated by each application - so you have to find some way to use the mouse/keyboard to get the application in a state where Ctrl+Home / Ctrl+End will function, then simulate it in the gesture. Code://Ctrl+Home - Click the bottom left corner of the window
//then move the mouse back to the previous location and send Ctrl+Home
var currentMouseLocation = sp.GetCurrentMousePoint();
var leftEdgeOfWindow = action.Window.Rectangle.Left + 1;
var bottomOfLeftEdge = action.Window.Rectangle.Bottom - 1;
var clickPoint = new Point(leftEdgeOfWindow, bottomOfLeftEdge);
sp.MouseClick(clickPoint, MouseButtons.Left, true, true);
sp.MouseMove(currentMouseLocation);
sp.SendKeys("^{Home}");
Code://Ctrl+End - Click the bottom left corner of the window
//then move the mouse back to the previous location and send Ctrl+End
var currentMouseLocation = sp.GetCurrentMousePoint();
var leftEdgeOfWindow = action.Window.Rectangle.Left + 1;
var bottomOfLeftEdge = action.Window.Rectangle.Bottom - 1;
var clickPoint = new Point(leftEdgeOfWindow, bottomOfLeftEdge);
sp.MouseClick(clickPoint, MouseButtons.Left, true, true);
sp.MouseMove(currentMouseLocation);
sp.SendKeys("^{End}");
Code://Firefox only - Change focus to the address bar,
//then send Tab twice to return focus to the web page
//and send Ctrl+End
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_L]);
sp.Sleep(20);
sp.SendVKey(vk.TAB);
sp.Sleep(20);
sp.SendVKey(vk.TAB);
sp.Sleep(20);
sp.SendKeys("^{End}");
Edited by user Wednesday, December 4, 2019 4:23:13 PM(UTC)
| Reason: Not specified
|