简体   繁体   English

按Fn键Python 3

[英]Press Fn key Python 3

I bought a new keyboard and everytime I turn on my computer I have to press Fn + 5 (3 times) to set the color I want for the backlighting, so I decided to try to script it. 我买了一个新键盘,每次打开计算机时,都必须按Fn + 5(3次)来设置背光所需的颜色,因此我决定尝试编写脚本。 First I tried with the pyautogui library: 首先,我尝试使用pyautogui库:

import pyautogui as pg
import time

for x in range(0,2):
    pg.hotkey('fn','5')
    time.sleep(0.2)

But that didn't work since it didn't recognize the fn key. 但这不起作用,因为它无法识别fn键。 Then I tried with the keyboard library and same problem. 然后我尝试了键盘库和同样的问题。 Lastly I tried with ctypes but there doesn't seem to be a virual key code for the Fn key. 最后,我尝试了ctypes,但似乎Fn键没有虚拟键代码。

Am I missing something or is there no way to automate a Fn + number press in windows? 我是否缺少某些东西,或者没有办法在Windows中自动按Fn +数字键?

There are keys for pressing fn+special keys: 有一些按键可以按fn +特殊键:

for example for volume control: 'volumedown', 'volumemute', 'volumeup' 例如音量控制:“ volumedown”,“ volumemute”,“ volumeup”

import pyautogui
pyautogui.press('volumeup')

All the keys are in a list that you can access by typing 所有键都在列表中,您可以通过键入来访问

print(pyautogui.KEYBOARD_KEYS)

output: 输出:

['\t', '\n', '\r', ' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 'accept', 'add', 'alt', 'altleft', 'altright', 'apps', 'backspace', 'browserback', 'browserfavorites', 'browserforward', 'browserhome', 'browserrefresh', 'browsersearch', 'browserstop', 'capslock', 'clear', 'convert', 'ctrl', 'ctrlleft', 'ctrlright', 'decimal', 'del', 'delete', 'divide', 'down', 'end', 'enter', 'esc', 'escape', 'execute', 'f1', 'f10', 'f11', 'f12', 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f2', 'f20', 'f21', 'f22', 'f23', 'f24', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'final', 'fn', 'hanguel', 'hangul', 'hanja', 'help', 'home', 'insert', 'junja', 'kana', 'kanji', 'launchapp1', 'launchapp2', 'launchmail', 'launchmediaselect', 'left', 'modechange', 'multiply', 'nexttrack', 'nonconvert', 'num0', 'num1', 'num2', 'num3', 'num4', 'num5', 'num6', 'num7', 'num8', 'num9', 'numlock', 'pagedown', 'pageup', 'pause', 'pgdn', 'pgup', 'playpause', 'prevtrack', 'print', 'printscreen', 'prntscrn', 'prtsc', 'prtscr', 'return', 'right', 'scrolllock', 'select', 'separator', 'shift', 'shiftleft', 'shiftright', 'sleep', 'space', 'stop', 'subtract', 'tab', 'up', 'volumedown', 'volumemute', 'volumeup', 'win', 'winleft', 'winright', 'yen', 'command', 'option', 'optionleft', 'optionright']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM