It’s a busy summer for Keegan-Michael Key, who stars in a new Netflix series and an Off-Broadway play, and while the roles couldn’t be more different, they both explore the bonds and boundaries of friendship.

In “Friends From College,” a new dramedy about the lives of 40-somethings, Key plays Ethan, a writer and Harvard alum who’s just realizing that the life he had figured out is actually coming apart at the seams. Premiering July 14, the ensemble cast includes Cobie Smulders as Ethan’s wife; Fred Savage as a gay college buddy; and Annie Parisse as another college pal and longtime lover — make that “friend with benefits from college.”

Then there’s director Sam Gold’s production of “Hamlet,” which stars Oscar Isaac as the moody titular Dane and Key as his BFF, Horatio. The inventive production opens downtown at the Public Theater on July 13 and runs through Sept. 3.

Key, 46, a Detroit native, is best known for his outsize sketch-comedy roles, like the ranting Coach Hines on “MadTV” and Obama Anger Translator Luther on Comedy Central’s “Key and Peele.”

Well, we certainly see a lot of you in the opening scene of “Friends From College.”

We certainly do, don’t we? We just jumped right on in.

It’s you and Annie Parisse in a sex scene. Have you ever had to get naked for a film crew before?

Actually, there was nudity in the very first film I ever made. The director said they could shoot it in such a way that I didn’t need to take my clothes off. But I was 25, so I was like, “No, no, I’m an artist. I’m gonna take my clothes off.” Now . . . 22 years later . . . [He laughs.]

It seems crazy to say it, but, for TV, a show about people in their 40s seems . . . almost revolutionary.

You’re right. It seems everybody in TV and commercial cinema is obsessed with the 18-to-35 demo — to the point where we literally call it “the demographic.” As if at age 36 we stop spending money. But us Gen X-ers and Gen Y-ers certainly have something to say about the world, and we’re gonna be running it soon.

Good luck with that.

Oh, I know. It’s a good time to examine where we are, this generation that’s been flying under the radar. We still sometimes talk about Baby Boomers, because it’s fascinating to see how hippies are aging. And we’re completely obsessed with Millennials. But there are these two “half-generations” in the middle that we’re not paying attention to, and this show is an exploration of that.

What do you think viewers will find most surprising?

There’s a darker edge. These characters are grappling with some existential questions, like “Am I a success?” And “How do I measure that?” And “Where is the joy in my life supposed to come from?” There’s a zany quality, but also quite a depth here, stuff that’s not reflected in the trailers. I hope people come for the wackiness and stay for the profundity.

Then there’s your other friend, “Hamlet’s” Horatio. Is this your first Shakespearean role?

My first since college. I’ve been a little busy pursuing something I never thought I’d pursue in a million years. [He laughs.] I’m an avid fan — I’m one of those people who’ll read Shakespeare for fun. So . . . this is my dream. I just happened to end up on this 19-year detour into sketch comedy. But this is what I always thought my career would be.

You’re an intriguing performer. You go from modern-day Ethan to Horatio . . . and all those comedic characters in between. How do you manage to be so . . . slippery?

I’m fortunate. One of my goals is to inhabit a character as fully as I can rather than be a movie star. I’ve always wanted to go the . . . how shall we say . . . the Johnny Depp route. The early De Niro route. As opposed to . . . Cary Grant, who never really played a character. He was fantastic as Cary Grant. But as much as I appreciate him, there’s no appeal in that for me. My brother gave me the greatest compliment once. He saw me playing a transgender character in the play “The Colored Museum,” and afterward he said, “That was, uh . . . I’m not sure how to, uh . . . ” He was completely flabbergasted. I think he finally sputtered out a sentence, saying, “I don’t understand how . . . you can do that and not be gay.” I just hugged him. That was the greatest compliment. It can’t get better than that. If I can continue to do that in my career, I’ve a good chance at not being pigeonholed. And that’d be . . .

Very unusual in Hollywood.

And very fulfilling.