Mine do the same thing...I think they are just curious...they peck at everything. I just tell them "I'm not a vending machine" I had a couple of girls that would peck me, then go into the breeding squat. Maybe they are just trying to get your attention.
Hens use their beaks for lots of purposes. The two big things are communication and food procurement.
Yes, one reason they peck on your legs is to get your attention. Usually, if you squat down and touch them or pick them up and hold them, this satisfies them.
If they seem to swarm around your legs, they may see freckles, blemishes, warts, moles, and small injuries. Examine your legs carefully and see if you have any of these things. My chickens happen to be adept at wart removal, and it's saved me the trouble of a visit to the doctor to have them taken off.