3
votes

How to get the right click context menu in a Windows application using Python, do not set the position of the cursor and when not focus that Windows application.

Context menu is not the Explorer context menu, it is the Windows application right click context menu.

enter image description here

1
app.UntitledNotepad.Edit.Click(button='right') works correctly, but the next command app.PopupMenu.MenuSelect('Paste') gets the Notepad window to the focus. Do you have the same kind of problem?Vasily Ryabov

1 Answers

2
votes

Here is an example for Notepad:

app.UntitledNotepad.Edit.Click(button='right') # works
app.PopupMenu.MenuSelect('Paste') # seems not working when Notepad is not in focus
# though it works when app.UntitledNotepad.SetFocus() is called before

app.PopupMenu.MenuSelect('Paste') may not work in such a case because probably WM_COMMAND can be sent to a focused window only. To get it to work use app.PopupMenu.MenuItem('Paste').ClickInput() though your app window will get to focus any way.


So finally there are 2 working examples. The first is:

app.UntitledNotepad.SetFocus()
app.UntitledNotepad.Edit.Click(button='right')
app.PopupMenu.MenuSelect('Paste')

The second is:

app.UntitledNotepad.Edit.Click(button='right')
app.PopupMenu.MenuItem('Paste').ClickInput()