People seem to be giving tips on how to stay awake (which is a good idea), but you asked how to keep alert while driving. FYI, once you're fatigued, yelling, slapping, and gum don't much help driving skills or prevent microsleep, a/k/a the "long [possibly permanent] blink." At the very least, accident research shows ... YMMV. Plus, it's worth wondering if cranking up Spanish for Tourists ("El gato es azul!" The cat is blue!") is ultimately distracting. If you need both hands to do something, your brain should probably be in on it, too.
In any event, about once every month or so, I have to make a 20-hour (each way) drive. Here's a few things that I have found to be helpful.
Yes, caffeine interferes with sleep. But, if you drink a cup of coffee immediately followed by a 20-minute nap chaser, you can exploit a quirk in the way both sleep and caffeine affect your brain to maximize alertness.
Dehydration is a big fatigue-causer. As you dehydrate, your blood thickens and moves more slowly through your veins. This means that your body is using oxygen at a slower rate, and thus you get sluggish.
"Are you serious?” Yes, a little. Excessive amounts of caffeine can cause nervousness, decrease concentration, and negatively affect hydration status (and, even if it doesn't increase volume, it can make you feel like you have to go). Incidentally, caffeine isn't the the only alkaloid that has cognitive enhancing effects. In fact, people who need to be both calm and alert with lightning reflexes (drivers; shooters) often opt for other choices (DMAE, for example). Likewise, avoid sugary energy drinks with high sugar content (where the sudden rise and fall of blood sugar levels can impact your ability to focus on the task at hand; plus a high sugar content can slow down absorption of water).
If you have it. Also known as Provigil. It's the drug of choice for fighter pilots, investment bankers, Silicon Valley execs, and other "no easy day"-types.
Fatigue is the seed; boredom is a fertilizer
If you want to stay alert through the slack moments, give yourself a series of mission oriented tasks. Cycle between looking ahead, then your mirrors, and back again. Get your whole brain involved by calling out everything you see on the road: Road signs car makes/models, even license plates. This will keep scanning the road in front of you. Refocusing your eyes multiple times prevents you from getting fixated on a spot in the distance and falling in to "highway hypnosis." If you're so inclined, get all Walter Mitty about it: Pretend you're on the run, check for tails, etc. (after which, feel free to annoy everyone by combat parking at rest stops).
Consider the scenic route
Traffic absolutely kills me, and adds to total travel effort. I don't care if taking the backroads doesn't save time: It's enough that it feels faster. Plan your stops in advance for fun places. Keep a camera handy for whatever suits your fancy — feral buildings, signs with bad kerning, amusing/ unintentionally ironic bumper stickers, whatever. It'll keep your mind alert.
This'll keep you focused
A trucker once told me that even if he's parked and inside a rest stop when someone hits his rig, he's still got to take a drug test. And that's "totally blacklisting, because 8, probably 9 out of 10 guys ain't on anything." True or not, the possibility freaks me right the fuck out.
Adjust your seat
Bad posture makes you tense; tension makes you tired. Adjust your seat's tilt, height, recline, distance from the wheel, lumbar support, and head rest; the steering wheel and peddle location; mirrors; arm rest; etc. You might also consider after-market seat cushions, steering wheel covers, neck supports, and the like. FYI, besides wearing comfortable clothes and shoes, take your wallet out of your back pocket. (As a bonus, the police will appreciate your wallet being out and open on the dash should they stop you.)
Don't drive in the passing lane
It probably won't help alertness, but it'll keep others from fantasizing about murdering you (I'm looking at you, all of Michigan and Illinois).
Breathing properly oxygenates the body, decreases tension, and heightens the nervous system. One of many tricks: Inhale and tense the sore/crapped muscle. Hold, hold, hold for five. Exhale and release tension for five. Repeat 3 times or so. When done, the blood rushes in to those muscles and joints, and it feels great.
wear sunglasses, and clean your windshield and lights (to minimize glare and eye fatigue).
Pick-up that shady-looking drifter
That's hours of excitement right there, wondering just what he's got in his bowling bag!
Lemon and peppermint are allegedly stimulating scents that help performance on tasks that required sustained concentration.
Use a cold pack
Rolling down the windows, turning up the AC are popular approaches. But a lower body temperature is also associated with sleepiness. Instead, put an instant cold pack or strip on the back of your neck or forehead.