You've got to decide whether you want to encourage begging by kids wherever you travel. If not, you probably shouldn't be handing out gifts that way.
Fortunately, there are other ways to do it. You can establish a real relationship with a family, a school, a village or another sort of organization, and give to them in either structured or casual ways. This can actually be beneficial, although you do need to pay attention to the underlying messages you're conveying without meaning to--messages like "I'm rich and you're poor and you should adore me and everything I do...." Which is much what makes throwing pens or candy out your 4x4 window so appealing to those who favor this sort of interaction.
I am totally supportive of the impulse to give something back to the areas in which we travel, which give us so much pleasure and so many learning opportunities. But handing out soccer balls and hacky sacks to kids who come clamoring around my bike probably won't do it for me. I'm always interested in hearing how others cope with the issue.
(hiding from the mid-day sun in Brazil)