Alternatively to the proposed Terminal commands, you can make your own shortcut key commands, that will work system-wide to shut down or restart your Mac
System Preferences > Keyboard > Shortcuts > App Shortcuts
Add new commands to All Applications for Restart… & Shut Down…
Note that those are ellipses, not 3 full stops [periods].
3 stops will not work.
Copy/paste them from here if you're not sure how to make them.
Choose any key commands you like, but make sure they don't conflict with anything else.
The slightly odd thing is that once you've done it, the menu itself 'grows' another two commands, without ellipses.
This doesn't appear to affect anything adversely, it just looks odd.