RanRag
RanRag

Reputation: 49537

Python : get master volume windows 7

I am trying to built an App in which user has to just scroll his/her mouse over the windows sound icon to change the sound level. Linux users are already familiar with this. I have divided my problem in these steps:

 1.) Get current audio device list using a python api.
 2.) Control the master voulme using the api.
 3.) Attach a mouse event listener to it.(Sorry i am from Java background).
 4.) Get mouse event listener method to do my work .

Plz suggest a proper python API to achieve my task.

And is this the correct approach towards my problem statement or there is a better way to approach this.

Upvotes: 3

Views: 2330

Answers (1)

Deviacium
Deviacium

Reputation: 371

For this purpose you could use PyWin32 http://sourceforge.net/projects/pywin32/ or ctypes. And your approach is pretty fine. Here's a simple example for mouse with pywin32:

import win32api
import win32con
def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
click(10,10)

and here's a similar one with ctypes:

import ctypes
ctypes.windll.user32.SetCursorPos(10, 10)
ctypes.windll.user32.mouse_event(2, 0, 0, 0,0)
ctypes.windll.user32.mouse_event(4, 0, 0, 0,0)

Ctypes is somewhat harder sometimes to figure out and debug (requieres ALOT of time on MSDN), but it's awesomely fast.

Upvotes: 2

Related Questions