I am running an application that uses pyautogui.moveTo() and pyautogui.click() for a long period of time (an hour+). To decrease the battery drain on my laptop, I'd ideally want the screen to turn off in this period, but because the autogui functions mimic using the mouse, the computer will not turn the screen off. I'm using Windows 10, and I'm not sure if I could use some functions from PyWin32 or WMI as demonstrated in this post, because the screen will brighten again when the mouse moves each time.
Having the laptop turning off and on the screen repeatedly doesn't seem like it would save too much power, but I'm not sure.
I am not sure this is what you want but many to all laptops have a brightness setting and windows devices definitely do. This should save some power on your device.
Related
SHORT VERSION:
I'm attempting to detect when my microphone is being captured by a program like Discord, preferably in Python, but I can't figure out how to do it. Any suggestions?
LONG VERSION:
I'm trying to write a program that will turn on an "On Air" light whenever my microphone is being used. Typically this would either be for Discord or Twitch. This is something Windows already monitors as well (Windows 10) because it displays a microphone icon down in the notifications tray and tells you what programs are using your microphone. Basically, whenever that icon notification is up, I want my light to be turned on.
The light is currently being run by sending serial commands through Python to an Arduino Nano, but I can only manually tell it to turn on or off.
I can't find a way to access windows privacy monitoring status or make any headway on just checking if a microphone is in use with Python. Any suggestions?
You can lock if the MicrophonIcon is displayed. Presice write an Pythonscript that locks if Pixel at the Position of the MicrophoneIcon having the Color off the MicrophonIcon. qt can do this. It has a python binding.
Get the Position of the MicrophonIcon( you can hover over it with the mouse and use a program to look the position up)
Get some Pixel Colors off the aria with qt
write a loop that checks if the Pixel Colors at the moment are equal to messured ones.
Con: if the Position off the Microphon changes(Screensize, other options that push it, not visable( fullscreen)) It will not work.
If you checke the yello lines in 2 loops it should define the Microphone icon nearly failsafe if the position isnt changing
I am developing a software in Python that generates static jpeg files, which are written to the file system. The software ist running at startup and gets triggered by some external and internal events, generates the corresponding jpeg image and should show it in fullscreen on the connected HDMI-screen without any visible user control or menu bar.
There is no window manager (Gnome, KDE, ...) installed and running. The device is a passive one and remotely controlled.
I am currently starting a feh process in order to view an image, and kill it before the next one is shown. It works, but is not very satisfying.
Do you have any better idea how I can get my Python 3 program to display the jpeg on the X Server?
Do you really need an X-Server? If you don't any GUI or mouse, you may be better writing the pictures into the framebuffers without X-Server. You can simply use fbi for this.
Use feh with one of the --bg- options. This sets the background of the root X window, and then exits. So you don't have to deal with killing feh to restart it, just call the command every time you want to change the image.
feh --bg-scale image1.jpeg
This doesn't work with some desktop environments (kde, gnome, xfce, and others), but will work with lightweight window managers (evilwm, goomwwm, etc.) and will also work with no window manager.
I'm trying to write an Xvfb-to-HTML5-canvas tool that will need to know when an X11 window changes so it can send a screen update to the client. Think of it like a web-based VNC or RDP but just for X11 windows (why send the whole desktop? =).
I thought there would be a straightforward way to do this via Xlib or xcb (xpyb) but in my experiments the best I've been able to do is detect when a window is created, destroyed, or moved. That's great and all but I need to know when the contents of windows change as well (imagine sending a keystroke to an xterm and having it appear frozen until you move the window).
If someone knows of a way to tell when the contents of an X11 window have changed I'd love to hear it! I'm open to creative solutions. For example, I tried using ffmpeg to stream x11grab through a fifo with regular checks to see if anything changed but it turned out to be extremely inefficient in terms of CPU utilization (it also seems to slow the whole system down even if nothing is going on).
I also tried just grabbing 15fps worth of screenshots in a loop while checking for changes in the most efficient way I could (e.g. does this cStringIO buffer match the last one?). That also was very CPU intensive.
The ideal solution would be for me to be able to watch the file descriptor of a socket and call a handler when there's a change in the X11 window. I'm willing to settle for detecting when the whole X11 screen has a change... That'd still be better than what I've got.
Any and all help with this is appreciated!
First of all, you can actually use vnc to track changes in just one window, not whole desktop. From x11vnc documentation:
-id windowid Show the X window corresponding to "windowid" not
the entire display. New windows like popup menus,
transient toplevels, etc, may not be seen or may be
clipped. Disabling SaveUnders or BackingStore in the
X server may help show them. x11vnc may crash if the
window is initially partially obscured, changes size,
is iconified, etc. Some steps are taken to avoid this
and the -xrandr mechanism is used to track resizes. Use
xwininfo(1) to get the window id, or use "-id pick"
to have x11vnc run xwininfo(1) for you and extract
the id. The -id option is useful for exporting very
simple applications (e.g. the current view on a webcam).
-sid windowid As -id, but instead of using the window directly it
shifts a root view to it: this shows SaveUnders menus,
etc, although they will be clipped if they extend beyond
the window.
-appshare Simple application sharing based on the -id/-sid
mechanism. Every new toplevel window that the
application creates induces a new viewer window via
a reverse connection. The -id/-sid and -connect
options are required. Run 'x11vnc -appshare -help'
for more info.
If you want to code similar functionality manually you need to use damage extension.
Here is simple example in javascript using node-x11 (sorry, I'm not sure about damage extension support in python)
var x11 = require('x11');
var X = x11.createClient(function(err, display) {
X.require('damage', function(Damage) {
var damage = X.AllocID();
Damage.Create(damage, parseInt(process.argv[2]), Damage.ReportLevel.NonEmpty);
X.on('event', function(ev) {
Damage.Subtract(damage, 0, 0);
console.log("window content changed!");
});
});
});
start it with window id as command line argument and you'll be notified whenever window content is changed.
I am making a gyro mouse. The driver script reads sensor input and moves mouse accordingly with win32api commands.
win32api.SetCursorPos((xStart-int(dh*xsensitivity),ypos))
When I open a full screen game such as Counter Strike Source, the mouse wont work at all. Only the click inputs function, but they cause to gun to point straight down and perform a kind of seizure.
Is there some way I can interface with whatever controls the mouse inside the game?
I'm not terribly familiar with Windows programming, but my best guess is that the video game (Counter Strike) is using the DirectInput (from DirectX) methods to read mouse travel. That is, it's using DirectInput to get mouse motion events, and the Python win32api.SetCursorPos is "warping" the cursor to the given location and not generating ANY intermediate movement messages.
You'll most likely need to use the MS Win32 API call SendInput to construct mouse movement messages and push them into the event queue at the OS level.
If you're familiar with .NET technologies, you might try using IronPython (a Python interpreter that can interact with the .NET runtime). In such case, the Input Simulator project at Codeplex has methods defined for pushing mouse movement events into the input queue.
How can I tell Windows not to do unhelpful pre-processing on tablet pen events?
I am programming in Python 2.6, targetting tablet PCs running Windows 7 (though I would like my program to work with little modification on XP with a SMART interactive whiteboard, and for mouse users on Linux/Mac). I've written a program which hooks into the normal Windows mouse events, WM_MOUSEMOVE etc., and writes on a canvas.
The problem is that the mouse messages are being fiddled with before they reach my application. I found that if I make long strokes and pause between strokes then the mouse messages are sent properly. But if I make several rapid short strokes, then something is doing unhelpful pre-processing. Specifically, if I make a down-stroke about 10 pixels long, and then make another downstroke about five pixels to the right of the first, then the second WM_MOUSEDOWN reports that it comes from exactly the same place as the first.
This looks like some sort of pre-processing, perhaps so that naive applications don't get confused about double-clicks. But for my application, where I want very faithful response to rapid gestures, it's unhelpful.
I found a reference to the MicrosoftTabletPenServiceProperty atom, and to CS_DBLCLKS window style, and I turned them both off with the following piece of Python code:
hwnd = self.GetHandle()
tablet_atom = "MicrosoftTabletPenServiceProperty"
atom_ID = windll.kernel32.GlobalAddAtomA(tablet_atom)
windll.user32.SetPropA(hwnd,tablet_atom,1)
currentstyle = windll.user32.GetClassLongA(hwnd, win32con.GCL_STYLE)
windll.user32.SetClassLongA(hwnd, win32con.GCL_STYLE, currentstyle & ~win32con.CS_DBLCLKS)
But it has no effect.
I tried writing a low-level hook for the mouse driver, with SetWindowsHookEx, but it doesn't work -- obviously the mouse messages are being pre-processed even before they are sent to my low-level Windows hook.
I would be very grateful for advice about how to turn off this pre-processing. I do not want to switch to RealTimeStylus -- first because it won't work on Windows XP plus SMART interactive whiteboard, second because I can't see how to use RealTimeStylus in CPython, so I would need to switch to IronPython, and then my code would no longer run on Linux/Mac.
Damon.
For raw mouse messages, you can use WM_INPUT on XP and later. Seven added some touch specific stuff: WM_GESTURE and WM_TOUCH