Lonely Boy is the first single from The Black Keys' 2011 album El Camino. The song is in standard tuning (EADGBE), but uses a pitch-shifting pedal to dive sixth string notes down an octave.
After an open sixth string E rings out, the guitar plays this catchy riff before the rest of the instrumentation joins in. Getting the timing of the pitch shift dive consistent without affecting the next note is the main challenge with this riff.
If you're using a pitch shifter pedal, set it to dive down one octave. Make sure to use the full sweep of the pedal to reach the octave below and then return to standard pitch.
If you're using a whammy bar, you'll need to learn the distance you need to depress the bar until you reach the octave below. Every guitar is different, depending on how it's set up, so take some time to get the feel of your own instrument
Get the sound
Use the bridge pickup to get some brightness here. Ideally, you should use a valve amp that's driven just to the point of mild overdrive.
You should also use a decent amount of pick attack, as well as picking slightly nearer to the bridge than normal. This will add presence and clarity to the sound while encouraging a little more overdrive from your amp.
Finally, you can try adding a little reverb or a slapback delay to the sound if you have a pedal to hand.