How do I take a screenshot of the keyboard viewer with modifiers (e.g. Alt Gr, Shift)?

You should be able to use Applications/Utilities/Grab.app for this kind of thing, it offers more kinds of capture including timed.