I'm trying to write a script that let's me check whether the Webcam and Microphone are in use. For the webcam I already managed to write something in Python, however so far I haven't found a good way to do the same for the microphone.
In Windows you have a dedicated setting in the SysTray that is showing up when your microphone is actually used by an app (and even showing which one):
So obviously Windows knows whether it's used at the moment (that's all I would need) and even which application is using it. However I did not find any way to read that information out in any way yet.
Is it possible to somehow get the data from Windows itself?
At this point, I don't even mind which language would be used for it, Python, C#, PowerShell or whatever.
PS: I know there might be ways to access the microphone wihtout it being shown in the SysTray, but this case is not relevant for what I'm trying to achieve.
I managed it now with the following approach - I'm just taking a screenshot of the desktop and check for the icon I expect to appear in the SysTray in case some app is using the microphone.
For this I used the package imagesearch that can be installed via pip:
pip3 install python-imageseach-drov0
Then I take a screenshot via that package and check whether the item is visible on the screen:
from python_imagesearch.imagesearch import imagesearch
pos = imagesearch(imagePath)
microphone_on = pos[0] != -1
if microphone_on:
print("Microphone is in use")
else:
print("Microphone is not in use")
The image defined in imagePath looks like this:
I found infos for the package on following page: https://brokencode.io/how-to-easily-image-search-with-python/
The recognition works very well and fast, but of course this might not be the best solution and works for simple cases where you just want to know whether anything is using the mic or not. It still would be better if there is some API available that could be asked, but it's better than nothing and solves my problem.
Related
What I am trying to do right now is to see my system settings and data from a python code. For example, I want to be able to print things like the timer of how long until my device goes to sleep/locks, or what kinds of antivirus are installed on it. For now, I have tested with windows-tools.antivirus which has seemed to work, but I wanted to be able to use it on Mac as well.
import windows_tools.bitlocker
result = windows_tools.bitlocker.get_bitlocker_full_status()
print(result)
^This is what I had tried which worked on a Windows device but I am looking for a Mac equivalent
I am trying to capture images from a Mightex cmos usb camera (SCE-B013-U) with Python 3.6.5 and opencv-python 3.4.3.18. The software came along confirms the camera works fine. But, cv2.VideoCapture(0).isOpened() is false. I am sure I am missing something, but I do not know what. Please help. Thanks a lot in advance.
For testing I have 1 camera installed on my setup that I know is opencv compatible with the command below:
print(cv2.VideoCapture(0).isOpened())
returns True for me, but if I unplug the camera, it returns False. False can imply that there is no camera available....
If the other answer (above) yields no result, perhaps the installed driver may not be compatible with opencv?
From the product description:
In addition, a user-friendly GUI based application software and an SDK
are provided for custom software development. A USB command set
protocol is also provided for non-Windows based application
Cannot help but to think that this company may be following a different standard to the one opencv typically uses. For example, many USB3Vision cameras will not work out of the box in the way you are attempting and require additional programming to return a NumPy style array image.
Additional support for my thinking is in the "EXAMPLE OF GRAPHICAL USER INTERFACE"
Many of the options I've seen in the GeniCam standard (USB3Vision).
Camera Mode (Continuous / Trigger), Exposure Control, Autoexposure Enable, etc
This is not to say that the camera is definitely is or is not one or the other, but the symptoms suggest the camera is not compliant to run out of the box using opencv in the way you want to.
You could try this 3rd party SDK instead to help verify.
I have no affiliation with them, but the ability to use their program for a (free) trial is very useful for helping to troubleshoot this issue.
Best of luck with getting your camera to work.
Maybe this will help, the official documentation states:
Sometimes, cap may not have initialized the capture. In that case,
this code shows error. You can check whether it is initialized or not
by the method cap.isOpened(). If it is True, OK. Otherwise open it
using cap.open().
I'm currently at a crossroads. I'm somewhat versed in Python (2.7) and would really like to start getting into GUI to give my (although mini) projects some more depth and versibility.
For the most part, my scripts don't use anything graphical so this is the first time I'm dipping my toes in this water.
That said, I've tried using pygame and tkinter but seem to fail at every turn to get something up and running (although I had some slight success with pygame)
Am I correct to understand that for both I need X started in order to generate any type of interface, and with that, so I need X to get any type of input (touchscreen presses)?
Thanks in advance!
In order to use tkinter, you must have a graphics system running. For Windows and OSX that simply means you need to be logged in (ie: can't run as a service). For linux and other unix-like systems that means that you must have X running.
Neither tkinter nor any of the other common GUI toolkits will write directly to the screen.
I'm gonna give an alternative answer. If you know HTML, CSS and Javascript (or have time to give it a try) I would recommend using Flask, http://flask.pocoo.org/.
With flask you can create websites but you can also (as I am using it) let it be your GUI. It will work on any device and looks really good :).
I'm trying to write something that catches the audio being played to the speakers/headphones/soundcard and see whether it is playing and what the longest silence is. This is to test an application that is being executed and to see if it stops playing audio after a certain point, as such i don't actually need to really know what the audio itself is, just whether or not there is audio playing.
I need this to be fully programmatic (so not requiring the use of GUI tools or the like, to set up an environment). I know applications like projectM do this, I just can't for the life of me find anything anywhere that denotes how.
An audio level meter would also work for this, as would ossiliscope data or the like, really would take any recommendation.
Here is a very similar question: record output sound in python
You could try to route your output to a new device with jack and record this with portaudio. There are Python Bindings for portaudio called pyaudio and for jack called PyJack. I have never used the latter one but pyaudio works great.
I am trying to write a cross-platform python program that would run in the background, monitor all keyboard events and when it sees some specific shortcuts, it generates one or more keyboard events of its own. For example, this could be handy to have Ctrl-# mapped to "my.email#address", so that every time some program asks me for my email address I just need to type Ctrl-#.
I know such programs already exist, and I am reinventing the wheel... but my goal is just to learn more about low-level keyboard APIs. Moreover, the answer to this question might be useful to other programmers, for example if they want to startup an SSH connection which requires a password, without using pexpect.
Thanks for your help.
Note: there is a similar question but it is limited to the Windows platform, and does not require python. I am looking for a cross-platform python api. There are also other questions related to keyboard events, but apparently they are not interested in system-wide keyboard events, just application-specific keyboard shortcuts.
Edit: I should probably add a disclaimer here: I do not want to write a keylogger. If I needed a keylogger, I could download one off the web a anyway. ;-)
There is no such API. My solution was to write a helper module which would use a different helper depending on the value of os.name.
On Windows, use the Win32 extensions.
On Linux, things are a bit more complex since real OSes protect their users against keyloggers[*]. So here, you will need a root process which watches one of[] the handles in /dev/input/. Your best bet is probably looking for an entry below /dev/input/by-path/ which contains the strings "kbd" or "keyboard". That should work in most cases.
[*]: Jeez, not even my virus/trojan scanner will complain when I start a Python program which hooks into the keyboard events...
As the guy that wrote the original pykeylogger linux port, I can say there isn't really a cross platform one. Essentially I rewrote the pyhook API for keyboard events to capture from the xserver itself, using the record extension. Of course, this assumes the record extension is there, loaded into the x server.
From there, it's essentially just detecting if you're on windows, or linux, and then loading the correct module for the OS. Everything else should be identical.
Take a look at the pykeylogger source, in pyxhook.py for the class and implimentation. Otherwise, just load that module, or pyhook instead, depending on OS.
I've made a few tests on Ubuntu 9.10. pykeylogger doesn't seems to be working. I've tryied to change the /etc/X11/xorg.conf in order to allow module to be loaded but in that specific version of ubuntu there is no xorg.conf. So, in my opiniion pykelogger is NOT working on ubuntu 9.10 !!
Cross-platform UI libraries such as Tkinter or wxPython have API for keyboard events. Using these you could map «CTRL» + «#» to an action.
On linux, you might want to have a look at pykeylogger. For some strange reason, reading from /dev/input/.... doesn't always work when X is running. For example it doesn't work on ubuntu 8.10. Pykeylogger uses xlib, which works exactly when the other way doesn't. I'm still looking into this, so if you find a simpler way of doing this, please tell me.
Under Linux it's possible to do this quite easily with Xlib. See this page for details:
http://www.larsen-b.com/Article/184.html