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

Notification

Icon
Error

Options
Go to last post Go to first unread
liuchina  
#1 Posted : Tuesday, October 22, 2019 1:00:15 AM(UTC)
liuchina

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/26/2018(UTC)
Posts: 73
China
Location: 北京

Thanks: 18 times
Was thanked: 1 time(s) in 1 post(s)

Hi rob:
Thank you very much for developing S + net, which can do a lot of work for users. When I use s + net, I often have such needs. If I activate another window or program while the S + net script is running, the script will not work properly. I mean, if I start and run a script that works in the chord window, even if I activate or use another window, I hope that script still works in the chrome running in the background.
I'm not good at scripting, I'm not sure it's a reasonable requirement, but I hope to get your reply. If possible, I will take the time to try to solve the problem.
Thank you very much.
Rob  
#2 Posted : Tuesday, October 22, 2019 2:00:09 AM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 28 times
Was thanked: 415 time(s) in 354 post(s)
If you're sending keystrokes or mouse events to the window, it will need to remain the foreground window as that is the only window which receives keyboard and mouse input.

While it is technically possible to send events via windows messages, it's extremely complicated and not very reliable/consistent; sometimes not even possible depending on the application.

For example, this script should work to show the Chrome Bookmarks bar (Control+Shift+B):
Code:
var chromeWindow = action.Window;

//Control Down
chromeWindow.PostMessageObj(0x0100, 0x11, 0x1D0001);
sp.Sleep(10);
//Shift Down
chromeWindow.PostMessageObj(0x0100, 0x10, 0x2A0001);
sp.Sleep(10);
//b Down
chromeWindow.PostMessageObj(0x0100, 0x42, 0x300001);
sp.Sleep(10);
//b Up
chromeWindow.PostMessageObj(0x0101, 0x42, 0xC0300001);
sp.Sleep(10);
//Shift Up
chromeWindow.PostMessageObj(0x0101, 0x10, 0xC02A0001);
sp.Sleep(10);
//Control Up
chromeWindow.PostMessageObj(0x0101, 0x11, 0xC01D0001);

However, because of how TranslateMessage works, it doesn't translate the "B" to the correct char code, because the system does not see the Control and Shift keys as being pressed down. So instead of Chrome receiving 2 for the WM_CHAR message, it receives 98, which is the same value it receives when you just press the letter "B" on the keyboard.

But this will send the text "test" to Chrome, if the window is active and a text area has focus:
Code:
var chromeWindow = action.Window;

//t Down
chromeWindow.PostMessageObj(0x0100, 0x54, 0x140001);
sp.Sleep(10);
//t Up
chromeWindow.PostMessageObj(0x0101, 0x54, 0xC0140001);
sp.Sleep(10);

//e Down
chromeWindow.PostMessageObj(0x0100, 0x45, 0x0120001);
sp.Sleep(10);
//e Up
chromeWindow.PostMessageObj(0x0101, 0x45, 0xC0120001);
sp.Sleep(10);

//s Down
chromeWindow.PostMessageObj(0x0100, 0x53, 0x01F0001);
sp.Sleep(10);
//s Up
chromeWindow.PostMessageObj(0x0101, 0x53, 0xC01F0001);
sp.Sleep(10);

//t Down
chromeWindow.PostMessageObj(0x0100, 0x54, 0x140001);
sp.Sleep(10);
//t Up
chromeWindow.PostMessageObj(0x0101, 0x54, 0xC0140001);
sp.Sleep(10);

Then I thought, maybe I could send a space message to Chrome even if it wasn't the active window, since that only scrolls the page and doesn't require a text area to have focus to receive the input:
Code:
var chromeWindow = action.Window;

//Space Down
chromeWindow.PostMessageObj(0x0100, 0x20, 0x390001);
sp.Sleep(10);
//Space Up
chromeWindow.PostMessageObj(0x0101, 0x20, 0xC0390001);
sp.Sleep(10);

But that did not work either, it only works when Chrome is active.

So you see, while it sometimes can be possible for some applications, very often it doesn't work and is hardly worth the amount of time it takes to try.

Trust me, I've spent a lot of time over the years on these types of things! There have been a few times where it worked, but it's usually rare.
liuchina  
#3 Posted : Tuesday, October 22, 2019 2:22:03 AM(UTC)
liuchina

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/26/2018(UTC)
Posts: 73
China
Location: 北京

Thanks: 18 times
Was thanked: 1 time(s) in 1 post(s)
Thank you for your reply.
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.