Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:获取主卷windows 7_Python_Windows_Audio - Fatal编程技术网

Python:获取主卷windows 7

Python:获取主卷windows 7,python,windows,audio,Python,Windows,Audio,我正在尝试构建一个应用程序,用户只需将鼠标滚动到windows声音图标上即可更改音量。Linux用户已经熟悉这一点。 我将问题分为以下几个步骤: 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).

我正在尝试构建一个应用程序,用户只需将鼠标滚动到windows声音图标上即可更改音量。Linux用户已经熟悉这一点。 我将问题分为以下几个步骤:

 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 .
请推荐一个合适的python API来完成我的任务


这是解决问题的正确方法还是有更好的方法。

为此,您可以使用PyWin32或ctypes。 你的方法很好。 下面是一个使用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)
这里有一个类似的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有时比较难理解,在MSDN上调试需要花费大量时间,但速度惊人。

请说明此问题被否决的原因。