Automating a context menu using Python when Lock Screen is on - python

I have the task to automate a Windows based application using Python. I was able to achieve many of those tasks using the pyautoit package - but there was one task that requires a context menu to appear on right-clicking in a window. I was not able to detect menu options using AutoIt. So I have used the Send function which sends Keyboard key signals. Using the below code I was able to achieve selecting the menu option I wanted:
autoit.send("{UP}")
autoit.send("{UP}")
autoit.send("{UP}")
autoit.send("{UP}")
autoit.send("{UP}")
autoit.send("{UP}")
autoit.send("{LEFT}")
autoit.send("{DOWN}")
autoit.send("{ENTER}")
The problem I am facing now is that the code would not work if my computer is locked (Ctrl+Alt+Del). Since AutoIt would not recognize that context menu, I am sure it cannot be done using that package. I want to know if there is any package in Python that I could use to achieve this task. I want the code to work even when the PC is locked.

As far as I know you can use the Control...(...)-functions while being in windows lock screen but you cannot use the Send(...) function.
There is a ControlSend(...) though, but you would need a ControlHandle/ID to use it.

Related

How can I click buttons in a windows GUI program using python?

I am writing a python script that automates running a program and performing different tasks within the program. My main problem is figuring out how to click buttons and interact with the GUI of the program to be controlled.
I am currently using the pyautogui library and using pyautogui.click(X,Y) to advance through prompts and click on different menus and menu items. The problem with this approach is that I am relying on a separate script to inform me of the coordinates of interest in my environment by telling me the coordinates of where my cursor is hovering. This probably will not work on other machines and just seems like a one case solution.
My question is how can I automate using a program in windows (clicking around) without having to hard code the exact position of the items I need to click?
For example, If I need to click a "ok" box to accept some setting, how can I make Windows grab the program window, read through the options and click what I need without any prior knowledge of the position of the dialog box and where the "Ok" button is located?
Code:
import pyautogui as gui
gui.click(x,y)
The way you can do this using pyautogui is with their locating methods. You will need a picture (for example of the OK box) and then you can have pyautogui find it on the screen and give you its coordinates. Check out the official documentation on this.

Detecting keypresses in Windows to automate window functions in python

I'm creating an application to automatically perform keystrokes into the same, multiple windows that are open at the same time. These windows are all child windows from a parent.
For example, there are four windows and I want to press a key that will send CTRL-K to them, then immediately send WIN+M to all of them. After some time, I want to press another key that will then send SHIFT+WIN+M, and then CTRL+O.
I'm stuck on capturing windows using EnumWindow and all of that. I'm familiar with callbacks, but a little confused on how to use them.
I'm also considering using pyWinAuto's SendKeys.
I do realize there are programs like X-Mouse Button Control that can do all of this for me, but I'm learning and this would be a fun exercise.
I would recommend using PyAutoit for this, it's fairly straightforward to use and it usually works well. Steps to install the package and a simple example can be found here :
https://pypi.python.org/pypi/PyAutoIt/0.3

Terminal equivalent for gui popup windows in python

I am going to write simple "to do list" app in python. One of the features will be possibility to configure notifications/reminders for tasks. If user will be using GUI I am going to use some popup windows, but what if he runs the app in the terminal, without any GUI? What would be the best equivalent for that? Is there a possibility to somehow notify the user?
I will be thankful for any guidance or at least direction, I tried searching for all variants of "terminal/console/text" + "notifications/popups" but I did not find anything interesting...

Python Image processing screenshots

I'm trying to write a program than will detect when my mouse pointer will change icon and automatically send out a mouse click. Is there a better way to do this than to take screenshots and parse the image for the mouse icon?
EDIT:
I'm running my program on windows 7.
I'm trying to learn some image processing and make a simple flash game i made automated.
Rules: when the curses changes shape, click to get a point.
Also what imaging modules for python will allow you to take a specific size screenshot not just the whole screen? This question has moved to a new thread: "Taking Screen shots of specific size"
The way to do this in Windows is to install either a global message hook with SetWindowsHookEx or SetWinEventHook. (Alternatively, you could build a DLL that embeds Python and hooks into the browser or its Flash wrapper app and do it less intrusively from within the app, but that's much more work.)
The message you want is WM_SETCURSOR. Note that this is the message sent by Windows to the app to ask whether it wants to change the cursor, not a message sent when the cursor changes. So, IIRC, you will want to put a WH_CALLWNDPROC and a WH_CALLWNDPROCRET and check GetCursorInfo before and after to see if the app has done so.
So, how do you do this from Python? Honestly, if you don't already know both win32api and friends from the pywin32 package, and how to write Windows message procs in some language, you probably don't want to. If you do want to, I'd start off with the (abandoned) pyHook project from UNC Assist. Even if you can't get it working, it's full of useful source code.
You should also search SO for [python] SetWinEventHook and [python] SetWindowsHookEx, and google around a bit; there are some examples out there (I even wrote one here somewhere…)
You can look at higher-level wrapper frameworks like pywinauto and winGuiAuto, but as far as I know, none of them has much help for capturing events.
I believe there are other tools, maybe AutoIt, that have all the functionality you need, but not in Python module. (AutoIt, for example, has its own VB-like scripting language instead.)

How to get in python the key pressed without press enter?

I saw here a solution, but i don't want wait until the key is pressed. I want to get the last key pressed.
The related question may help you, as #S.Lott mentioned: Detect in python which keys are pressed
I am writting in, though to give yu advice: don't worry about that.
What kind of program are you trying to produce?
Programas running on a terminal usually don't have an interface in which getting "live" keystrokes is interesting. Not nowadays. For programs running in the terminal, you should worry about a usefull command line User Interfase, using the optparse or other modules.
For interative programs, you should use a GUI library and create a decent UI for your users, instead of reinventing the wheel.Which wouldb eb etter for what you ar trying to do? Theuser click on an icon,a window opens on the screen, witha couple of buttons on it, and half a dozen or so menu options packed under a "File" menu as all the otehr windws on the screen - or - a black terminal opens up, with an 80's looking text interface with some blue-highlighted menu options and so on?. You can use Tkinter for simple windowed applications, as it comes pre-installed with Python + Windows, so that yoru users don't have to worry about installign aditional libraries.
Rephrasing it just to be clear: Any program that requires a user interface should either se a GUI library, or have a WEB interface. It is a waste of your time, and that of your users, to try and create a UI operating over the terminal - we are not in 1989 any more.
If you absolutely need a text interface, you should look at the ncurses library then. Better than trying to reinvent the wheel.
http://code.activestate.com/recipes/134892/
i think it's what you need
ps ooops, i didn't see it's the same solution you rejected...why, btw?
edit:
do you know:
from msvcrt import getch
it works only in windows, however...
(and it is generalised in the above link)
from here: http://www.daniweb.com/forums/thread115282.html

Categories