-Beat- ...What?
Comedy in a semi-serious campaign is often times, in my opinion, funnier than if you try to go full bore into slapstick wackiness, and that is due to one time-tested principle, the Only Sane Man (TM). Even in grim and dark fantasy, in RPGs there are tons of things that happen that either don't make a whole lot of sense or are great sources of incredulity for people. The adventures that happen are fairly absurd by default- our protagonists are much like those in an old Greek legend- beholden to an indifferent god (the GM) and the Fates (random dice numbers). *
*Note that I'm being a little facetious when I call the GM an indifferent God.
So where, then, does the comedy come from? From the reactions of the characters that are put into these absurd situations. Don't punish players for snide remarks in character, for lamenting their plights, or for just maintaining a level of sarcasm about the absurdity of their misfortunes.
Inconvenience instead of Harm
The best examples I can give of the same subject manner but with different tone are two campaigns I've personally been involved in- one I ran and attempted to evoke emotion out of my players, the other I played in.
In scenario 1, I GM'ed a modern game where my players had magic powers and were uncovering that the mayor of the town they lived in was a murderous loony consorting with elder gods for destructive power. One of my players really wanted to get this guy, and attempted to threaten the mayor's family to do so. In response, the mayor killed his own family and sent the remains to my player. It angered him. It was a dark moment in our campaign, and got some real pathos. My players really wanted to see the mayor brought to justice because he harmed innocent people just to make a point.
In scenario 2, I was playing a ranger in a D&D game. I and two of my companions were captured by a hobgoblin town because we were causing a bit of a ruckus and killing their scouts. My character, who had done much of the damage, was nailed to a wall by his ankles upside-down. Now, this could be a tortuous moment that is full of darkness and cruelty, but instead I was allowed to play it a littler differently. Mainly-
"Welp...let's think, self. How did we end up here. Oh yes, by being stupid, I remember." I try to pull myself off of the wall and fail the roll. "OWWWWWW Ow ow ow. Ok...ok we're not doing that again."
Two distinctly dark scenarios, two very different reactions from the players because one set are allowed to bring levity to the situation while the other set keeps seeing how much farther the villain will go into depravity.
NPCs can do it too
And if things are getting a little too dark, don't forget that at any time, really any time, you can bring in an NPC that cracks jokes at the PCs or villain's expense. Those types of characters really lighten the mood without shifting the overall tone of the game.