我一直在使用pynput。

发布于 2025-01-23 15:24:49 字数 1371 浏览 5 评论 0原文

大家好,我是9岁的库尔特·李(Kurt Lee),我想问一下如何使用pynput键盘设法修复此音量栏。

from pynput.keyboard import Key, Listener
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume



def volume_controller(control):  #
    devices = AudioUtilities.GetSpeakers()
    interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
    volume = cast(interface, POINTER(IAudioEndpointVolume))
    vol = volume.SetMasterVolumeLevel(control, None)
    return vol

# Volume Bar
VolumeMax = "▁ ▂ ▃ ▄ ▅ ▆ █ 100%" + str(volume_controller(-0))
# Volume86 = "▁ ▂ ▃ ▄ ▅ ▆ 86%" + str(volume_controller(-2.3))
# Volume72 = "▁ ▂ ▃ ▄ ▅ 72%" + str(volume_controller(-5))
# Volume58 = "▁ ▂ ▃ ▄ 58%" + str(volume_controller(-8))
# Volume44 = "▁ ▂ ▃ 44%" + str(volume_controller(-12.2))
# Volume30 = "▁ ▂ 30%" + str(volume_controller(-17.9))
# Volume16 = "▁ 16%" + str(volume_controller(-26.5))
VolumeZero = "Muted" + str(volume_controller(-60))


def check_key(key):
    keyword = key
    if keyword is Key.up:
        print('UP')
        print(VolumeMax)

    elif keyword is Key.down:
        print("Down")
        VolumeZero


# Collect events until released
with Listener(on_press=check_key) as l:
    l.join()

我一直在修复一个星期时遇到困难,我非常需要帮助。例如,我目前的音量是100%,即最大音量,我想通过单击下降来将其降低到86%,然后下一个是将其提高到100%或更低至72%。

Good day everyone, I am Kurt lee, 9 years old and I would like to ask how can I manage to fix this volume bar using pynput keyboard.

from pynput.keyboard import Key, Listener
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume



def volume_controller(control):  #
    devices = AudioUtilities.GetSpeakers()
    interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
    volume = cast(interface, POINTER(IAudioEndpointVolume))
    vol = volume.SetMasterVolumeLevel(control, None)
    return vol

# Volume Bar
VolumeMax = "▁ ▂ ▃ ▄ ▅ ▆ █ 100%" + str(volume_controller(-0))
# Volume86 = "▁ ▂ ▃ ▄ ▅ ▆ 86%" + str(volume_controller(-2.3))
# Volume72 = "▁ ▂ ▃ ▄ ▅ 72%" + str(volume_controller(-5))
# Volume58 = "▁ ▂ ▃ ▄ 58%" + str(volume_controller(-8))
# Volume44 = "▁ ▂ ▃ 44%" + str(volume_controller(-12.2))
# Volume30 = "▁ ▂ 30%" + str(volume_controller(-17.9))
# Volume16 = "▁ 16%" + str(volume_controller(-26.5))
VolumeZero = "Muted" + str(volume_controller(-60))


def check_key(key):
    keyword = key
    if keyword is Key.up:
        print('UP')
        print(VolumeMax)

    elif keyword is Key.down:
        print("Down")
        VolumeZero


# Collect events until released
with Listener(on_press=check_key) as l:
    l.join()

I've been having trouble fixing this for a week and I badly need help please. For example, my current volume is 100% which is the Volume max, and I would like to lower it to 86% by clicking down then the next one is to go up to 100% or lower to 72%.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文