Nerves can be stimulated by various things.
When you hit your "funny bone, " you are stimulating your ulnar nerve in your elbow. When you poke your eye
, you are stimulating your optic nerve in a similar fashion, causing the sparkly lights (and a bit of pain).
Answer assisted by David Miller, Medical Student