I'm creating a program to set my keyboard and mouse brightness according to my screen brightness.
The issue is that I don't know how to get my screen brightness (I know that i can set my screen brightness with this line:
wmi.WMI(namespace='wmi').WmiMonitorBrightnessMethods()[0].WmiSetBrightness(desired_brightness, 0))
But I want to know how to get the brightness instead of changing it.
Maybe I can use one of the windows dlls with ctypes or maybe I can do this with wmi but i don't really understand how it works.
If you have any idea on how to do that, please tell me.
Try WmiMonitorBrightness()[0].Like:
import wmi
print(wmi.WMI(namespace='wmi').WmiMonitorBrightness()[0])
This has the same result with my device:
Related
I would like to show an image with transparent background to indicate something when a key combination is pressed.
Let's say I pressed ctrl+f3, I trigger a python script. Is there anyway I can make that happen?
What python library can I use to show an image without window border and background?
I have figured out how to trigger the file on key press. How to I deal with the (imshow) thing?
Thank you.
show an image without window border and background
This sound like task for some GUI library. There are many available but you would need test them in order to find which one can do it. First feature is generally known as frameless or borderless window. tkinter which ships with python has ability to work this way, see for example tutorialspoint.com tutorial, though I do not know how it will work with alpha channel of your image.
Is there a way to control screen brightness through Python? For example, I'm using Tkinter right now, and I'm wondering if there is a way I can program a button in tkinter to increase the brightness of the screen (and make another button that decreases the brightness of the screen)?
EDIT: I'm using a Windows computer, it's on Windows 10, but I also need it to work on Windows 7 too.
I used the WMI library and it really worked fine. Here is the code, but this is for Windows. I think it is OS specific so if it doesn't work for you, you should look for a better solution.
import wmi
brightness = 40 # percentage [0-100] For changing thee screen
c = wmi.WMI(namespace='wmi')
methods = c.WmiMonitorBrightnessMethods()[0]
methods.WmiSetBrightness(brightness, 0)
In tkinter you will not be able to adjust screen brightness. You might be able to make a macro and have your python program access it. Also with desktop monitors brightness is set by the monitor so depending on your model you will probably not be able to make any change at all. Good luck :)
Here is a link on using macros. Check it out and maybe find a way to control screen.
I have the same problem as here: Screen displays only in top left corner of window
The pygame container is messed up by the high resolution retina screen. I have searched around and haven't found any one with an answer other than "change your resolution".
Is it possible to fix this in the game, so that the player doesn't have to fix it themselves? Either fixing the bug in pygame or resizing the resolution when the game starts? Maybe it could work only in fullscreen somehow?
TO CLARIFY: I don't want to have to change the screen resolution manually, but within the pygame-code.
I don't know if you've figured this out at all yet as it's been a while. But you can enable low resolution mode for the pygame window in the Macs application settings. Then you don't have to change your resolution every time. I still haven't figured out how to fix this in code though.
https://support.apple.com/en-us/HT202471
Edit: I'm assuming it's a Mac you're using.
I am afraid there isn't any way. pygame hasn't been updated for a while and I think development has stopped. I ran into the same problem and ended up dealing with using a program called setresx when necessary. The problem can also be fixed by hooking up your computer to an external monitor. I know you can get some portable ones that you can put on the side of your screen.
As to changing the code, as far as I'm concerned it isn't pygame that there is anything wrong with, but technically the screen. That said, you might be able to change the library itself to handle the issue.
I am trying to understand how I can use PIL in Python 2.7 to search the whole screen for a certain image and click on it. I've been searching around and haven't been able to find a solution. I want to create a small GUI with one button in the middle of it that when clicked will search the entire screen for a predefined image. Once the image is found the program will then click in the centre of it and end. In short the program will detect if an image is present on the users screen and click it.
I did find an interesting bit on Sikuli, but that doesn't help me because it's unable to export to an .exe.
The image that the program will look for will most likely be in the same place each time it searches, but I didn't want to hard-code the location as it has the potential to move and I don't want that being an issue later on.
What I need is the code method I would use to search for the image on screen and send back the cords to a variable.
Image explanation/example:
Reference image of rifle:
PIL is the wrong tool for this job. Instead you should look into openCV (open source computer vision), which has fantastic python bindings. Here is a link to an example (in C but should be easy to redo with the python bindings) that does what you are looking for, but even allows the image to be rotated, scaled, etc.
http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html
http://docs.opencv.org/doc/tutorials/features2d/detection_of_planar_objects/detection_of_planar_objects.html
Edit:
I assume you are using windows, as your example image looks like window. In this case you can use:
from PIL import ImageGrab
pil_img = ImageGrab.grab()
opencv_img = numpy.array(pil_img)
then use opencv to process the image to find sub image you are looking for.
If you want to do this cross platform, then you will need to use wxWidgets to do the screengrab: https://stackoverflow.com/a/10089645/455532
Even I wanted to do the same but using different module - pyautogui. I finally found the solution for my problem and I am sure this solution will also help you.
You have to just go to this webpage and read the locate function topic completely
and you'll be able to solve your problem.
I recommend you give a look on PyAutoGUI, a well documented library to control mouse and keyboard, also can locate imagens on screen, find the position, move the mouse to any location and clicks on location, also can simulate drag and drop, type on input fields, give double clicks and much more.
I want to take a print screen of a particular window on my PC by running the python program and it taking that screen shot, before cropping it and comparing its hex value to other hex values in a SQL server.
I have thought about letting it wait 10 seconds whilst I get the other window up and then start taking the print screens continuously until one matches.
I was just wondering if I can use python to maximize that particular window that I want to print screen automatically and then have it take a print screen.
If not, could I take a print screen (a picture) of a window that is minimized? (I think this is impossible)..
Thanks!
If you do a quick Google search, you will find this helpful tutorial that uses PIL to take a screenshot of a desktop:
http://www.blendedtechnologies.com/quick-screenshots-script-python-pil/38
Assuming you're on Windows, you would need to use PyWin32 (or possibly pywinauto) to get the window you want. These two links will help with that:
Get HWND of each Window Python
http://timgolden.me.uk/python/win32_how_do_i/find-the-window-for-my-subprocess.html
Then you could use MoveWindow to resize the window you found before taking the screenshot:
How can I get the window focused on Windows and re-size it?