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

Notification

Icon
Error

Options
Go to last post Go to first unread
2014218866  
#1 Posted : Sunday, July 28, 2019 2:12:34 AM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 60
China

Thanks: 10 times
Dear, Rob
The following gesture works only when I activate the current window by left-clicking.
When I click on the desktop by left-clicking and then execute the gesture in other windows,
it is still recognized as the desktop.


Code:
if(action.Control.HWnd.ToInt32() == sp.DesktopWindowListView().HWnd.ToInt32()) {
            //do nothing
}else{
sp.SendKeys("%{F4}")
//action.Window.SendClose();
}


UserPostedImage

UserPostedImage
Rob  
#2 Posted : Sunday, July 28, 2019 7:13:12 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 455
United States

Thanks: 5 times
Was thanked: 88 time(s) in 76 post(s)
This is behaving how you have the script coded.

It is comparing the Control below the mouse cursor to the Desktop. Since the mouse is over the Explorer window (whether it is the active window or not), the Control.HWND does not match the Desktop HWnd, so it executes your else {} and sends Alt+F4.

Since the Desktop is the active window, it receives the Alt+F4 command and shows the Shutdown Windows prompt. Sending key strokes are always received by whatever window currently is active/has focus. That is why action.Window.SendClose() would work even if the window is not active, since it posts a message directly to the window. Of course, some applications may not respond to this command and Alt+F4 might be needed.

There are two ways to resolve this:

  1. Enable the option Options > General > Always Activate Window Where Gesture Began, this will ensure the window below the gesture start is activated before any action script is executed

  2. Use the script below, which will do the same thing as the above option, but instead of all scripts, it will only do it for this action/script

Code:
if(action.Control.HWnd.ToInt32() == sp.DesktopWindowListView().HWnd.ToInt32()) {
    //do nothing
} else {
    //If the click did not happen on the desktop and the active window is not 
    //the window where the click occurred, active the window below the mouse
    //before sending Alt+F4
    if(sp.ForegroundWindow().HWnd.ToInt32() != action.Window.HWnd.ToInt32()) {
        action.Window.Activate();
    }
    sp.SendKeys("%{F4}")
    //action.Window.SendClose();
}


thanks 1 user thanked Rob for this useful post.
2014218866 on 7/29/2019(UTC)
2014218866  
#3 Posted : Monday, July 29, 2019 8:05:18 AM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 60
China

Thanks: 10 times
Thank you, Rob.
Both schemes work well. I have one last question here. Is there a way to make the following hotkeys work properly?

UserPostedImage
Rob  
#4 Posted : Monday, July 29, 2019 9:10:33 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 455
United States

Thanks: 5 times
Was thanked: 88 time(s) in 76 post(s)
That is a little tricky. While you can sort of trick it into working, I will state that this may only work with some applications.
Code:
//Release the Alt key since you're still pressing it
sp.SendAltUp(); 
//Send Alt Down then Up to escape menu activation
sp.SendAltDown(); 
sp.SendAltUp();
//Send the Left arrow key
sp.SendVKey(vk.LEFT);
//Set the Alt key as pressed down again, so you can press 
//the hotkey again without releasing Alt first
sp.SendAltDown(); 

Ultimately, pressing the Alt key can initiate a menu/item activation sequence, which requires you to press and release the Alt key to escape from, which is what the above script attempts to do so the Left key can be sent by itself.
2014218866  
#5 Posted : Tuesday, July 30, 2019 5:03:43 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 60
China

Thanks: 10 times
I know what you mean, because ALT is used as the modifier key in the script, so it can't work properly in all software.
It seems that this hotkey can't work properly. Thank you, Rob.
Rob  
#6 Posted : Wednesday, July 31, 2019 5:45:07 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 455
United States

Thanks: 5 times
Was thanked: 88 time(s) in 76 post(s)
Did you try placing the vk.LEFT line with this instead?

sp.SendModifiedVKeys([vk.LMENU], [vk.LEFT]);
2014218866  
#7 Posted : Wednesday, July 31, 2019 9:32:27 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 60
China

Thanks: 10 times
Yeah, I did, but it didn't work on my computer. So I give it up.
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.