Automate windows operations to run when an F key is pressed

Hello community
Is there any way to automate a windows operation (eg sleep computer) when user presses an F key from the keyboard?
How can this be scheduled?

Thanks in advance…

I’m afraid it’s not a PowerShell solution but have a look at AutoHotKey.