Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Context menu in specific window
#1
I would like to know the equivalent code of the following QM code in LA.
This involves a lot of things, and as a sample, it would be very helpful for those who already have a grasp of QM.
Thank you in advance

Feature description:
In the notepad2(https://www.flos-freeware.ch/notepad2.html) window, depending on whether text is selected or not, right-clicking will display different menus

Function FFS_NP_Editor
Trigger #R //FFS_NP_Editor     Help - how to add the trigger to the macro
 
Code:
Copy      Help
;/
function# iid FILTER&f

if(wintest(f.hwnd "" "Notepad*"))
,if(childtest(f.hwnd2 "" "Scintilla"))
,,if !SendMessageW(f.hwnd2 SCI.SCI_GETSELECTIONEMPTY 0 0)
,,,ret "Select_NP" ;;Text selected
,,else
,,,ret "Empty_NP" ;;No text selected

ret -2

Menu Select_NP
 
Code:
Copy      Help
S_test1 :sub.Sub1 * findacc.ico
|
>S_test2 * findacc.ico
,S_test21 :sub.Sub2 * findacc.ico
<

#sub Sub1 m
paste "S_test1"

#sub Sub2 m
key "S_test21"

Menu Empty_NP
Code:
Copy      Help
E_test1 :sub.Sub1 * findacc.ico
|
>E_test2 * findacc.ico
,E_test21 :sub.Sub2 * findacc.ico
<

#sub Sub1 m
paste "E_test1"

#sub Sub2 m
key "E_test21"


Attached Files
.qml   Menu_NP.qml (Size: 3 KB / Downloads: 93)
#2
Code:
Copy      Help
    //add this function in file "Mouse triggers". Or add its code to another function in that file.
    [Triggers]
    void Example_mouse_trigger_with_FilterOf_and_menu() {
        //Triggers.Of.Window(cn: "Notepad*"); //optional here, because the Triggers.FuncOf function does the same
        
        wnd childWindow = default; //we use this variable to pass the child window handle to the trigger action
        Triggers.FuncOf.NextTrigger = o => { //like a QM filter function. https://www.libreautomate.com/api/Au.Triggers.TriggerFuncs.html
            var mta = o as MouseTriggerArgs;
            if (mta.Window.ClassNameIs("Notepad*")) {
                childWindow = wnd.fromMouse(WXYFlags.NeedControl);
                if (childWindow.ClassNameIs("Scintilla")) return true;
            }

            return false;
        };

        
        Triggers.Mouse[TMClick.Right, flags: TMFlags.ButtonModUp] = o => { script.run(@"Example_mouse_trigger_with_FilterOf_and_menu.cs", $"{childWindow.Handle}"); };
        
        //Triggers.Of.AllWindows();
    }

Code:
Copy      Help
// script "Example_mouse_trigger_with_FilterOf_and_menu.cs"
var childWindow = (wnd)args[0].ToInt();

childWindow.Focus();

var m = new popupMenu("f2dde795-cd80-4ee3-982a-67a95d3abbf5");
if (0 == childWindow.Send(2650)) { //SCI_GETSELECTIONEMPTY. https://github.com/qgindi/LibreAutomate/blob/master/Au.Controls/KScintilla/Sci%20API.cs
    m["S_test1"] = o => { print.it(o); };
    m.Separator(); //LA menus can have only horizontal separators
    m.Submenu("S_test2", m => {
        m["S_test21"] = o => { print.it(o); };
    });
}
else {
    m["E_test1"] = o => { print.it(o); };
    m.Separator(); //LA menus can have only horizontal separators
    m.Submenu("E_test2", m => {
        m["E_test21"] = o => { print.it(o); };
    });
}

m.Show();
#3
The same without FuncOf.

Code:
Copy      Help
    [Triggers]
    void Example_mouse_trigger_with_FilterOf_and_menu() {
        wnd childWindow = default; //we use this variable to pass the child window handle to the trigger action
        Triggers.Of.Window(cn: "Notepad*", also: o => { childWindow = wnd.fromMouse(WXYFlags.NeedControl); return childWindow.ClassNameIs("Scintilla"); });
        Triggers.Mouse[TMClick.Right, flags: TMFlags.ButtonModUp] = o => { script.run(@"Example_mouse_trigger_with_FilterOf_and_menu.cs", $"{childWindow.Handle}"); };
        Triggers.Of.AllWindows();
    }


Forum Jump:


Users browsing this thread: 1 Guest(s)