Apple does not make it easy to very rapidly toggle between the two F1 - F12 vs. Brightness - Volume Up keyboard modes.
Fortunately, this can be automated via the Shortcuts scripting system.
Run Shell Script
defaults write -g com.apple.keyboard.fnState -int $(( ! "$(defaults read -g com.apple.keyboard.fnState -int)" ))
/System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u
We've published this as a premade Shortcut script / widget / menulet.
https://github.com/mcandre/dotfiles/blob/main/src/toggle-function-keys.shortcut