I've had ppl trying to pet Zoey without asking. I just take a step back and tell them Zoey isn't really friendly. I usually watch for body language. I think I can tell when someone doesn't want their dog touched so I just comment on how cute they are and move on.
I did catch myself wanting to pet someone elses pet without asking first. I'd extend my hand and half way, I pull back realizing I didn't ask. LOL And all the times I did ask, the owners were really nice and allowed me to pet/scratch their pups. I usually scratch/massage behind the ear knowing most dogs like that.