'How to trigger Fn + F8 using a script?

I have tried pyautogui, pynput, and keyboard PyPI Packages. I want to trigger Fn + F8 key using python script. The below code is not working...

import pyautogui
pyautogui.press('fn+f8')

Please suggest any other technique to trigger fn + f8 using any script. It shouldn't be manual intervention...



Solution 1:[1]

according to the Documentation of PyAutoGUI, you should be able to do that using:

pyautogui.keyDown('fn')
pyautogui.press('f8')
pyautogui.keyUp('fn')

Solution 2:[2]

Try this, it's already in pyautogui.

from pyautogui import hotkey

hotkey('fn', 'F8')

This worked on every system I tried it on.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 D3M0N1K
Solution 2 Codeman