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 8:12:34 AM(UTC)
2014218866

Rank: Advanced Member

Reputation:

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

Thanks: 19 times
Was thanked: 1 time(s) in 1 post(s)
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 1:13:12 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 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 2:05:18 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

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

Thanks: 19 times
Was thanked: 1 time(s) in 1 post(s)
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 3:10:33 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)
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 11:03:43 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

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

Thanks: 19 times
Was thanked: 1 time(s) in 1 post(s)
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 11:45:07 AM(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)
Did you try placing the vk.LEFT line with this instead?

sp.SendModifiedVKeys([vk.LMENU], [vk.LEFT]);
2014218866  
#7 Posted : Thursday, August 1, 2019 3:32:27 AM(UTC)
2014218866

Rank: Advanced Member

Reputation:

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

Thanks: 19 times
Was thanked: 1 time(s) in 1 post(s)
Yeah, I did, but it didn't work on my computer. So I give it up.
soooulp  
#8 Posted : Tuesday, December 28, 2021 9:18:28 AM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
This is behaving how you have the script coded.

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();
}




I need to set it in a Hotkey and use the Touchpad Gesture program Gesturesign to send Alt+F4.

Could the Window under the mouse (not the foreground window) be active when executing the Hotkey?

Rob  
#9 Posted : Tuesday, December 28, 2021 5:07:25 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)
Quote:
Could the Window under the mouse (not the foreground window) be active when executing the Hotkey?

Sure, this should do it:
Code:
sp.WindowFromPoint(sp.GetCurrentMousePoint(), true).Activate();


thanks 1 user thanked Rob for this useful post.
soooulp on 12/29/2021(UTC)
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.