You didn't say which OS and desktop you're using. Hatari is developed on Linux (that's what Hatari developers have).
If you have a desktop keyboard shortcut for Alt-F4, and it doesn't work, I don't think that's a Hatari problem, but likely a bug in your desktop. It might be a bug also in your libSDL version, depending on what even that key is supposed to provide.
(You didn't say which version of libSDL you're using, I have libSDL v2.0.5 and with that, Alt-F4 closes Hatari just fine in XFCE desktop.)
AltGr-Q works fine for me as long as Hatari doesn't have a dialog open, in that case you just have to close the dialog first (e.g. with Enter). There are some rare cases where Hatari's outputting errors about what's running inside emulation so fast that it's not very responsive. Do you see any such output when you run Hatari from console? (if you're using Windows, console requires giving Hatari -W option)
If you want your controller to output key codes, that's something you need to do outside of Hatari. I think there are some programs on Linux to do that.