A sharp (♯) raises a note by a half step, a flat (♭) lowers it, and a natural (♮) cancels either. An accidental in front of a note lasts only to the end of that measure, then stops applying on its own.
A half step is the next key over, whatever its color. A half step up from C is the black key immediately to its right — but a half step up from E is F, a white key. "Sharp means black key" is an approximation that breaks in two places.
The highlighted black key is C♯ seen from the C on its left and D♭ seen from the D on its right — one key, two names.
To find a sharp on the keyboard, go to the white key with the same letter and move one key to the right; for a flat, move one key to the left. A♭ is therefore the black key just left of A, and G♯ the black key just right of G — one key with two names. Where no black key lies between two white keys (E and F, B and C), E♯ is simply F and C♭ is simply B.
A♭ and G♯ are this one key.The sign goes to the left of the note head, not the right. A natural cancels an accidental earlier in the same measure.
An accidental applies to every later note on that same line or space within the measure — including one tied across the bar line. It does not carry to other octaves: writing F♯ low down does not sharpen the F an octave above it.
Common questions
What is a natural sign?
A natural sign (♮) cancels a sharp or flat, whether it came from the key signature or from earlier in the measure. The note goes back to its plain letter name, which is always a white key.
Where is A-flat on the piano?
On the black key immediately to the left of A. It is the same key as G-sharp, just right of G; the key signature and the surrounding notes decide which of the two names the music spells.
Does a sharp last the whole measure?
It lasts until the next barline, but only for that pitch in that octave. After the barline the note returns to the key signature, unless it is tied across the barline, in which case the tied note stays altered.