Toggle the "Use all F1, F2, etc. keys as standard function keys" option in macOS System Preferences.
Thanks to MrSimonC, the initial version code was taken from this project:
Project Path: https://github.com/MrSimonC/Toggle-Mac-Function-Keys
Tested with:
macOS Sequoia developer beta macOS Sonoma, 14.2.1 January 2024 macOS Ventura, 13.2 January 2023 macOS Monterey, 12.6.2, December 2022 macOS Big Sur, 11.4, June 2021