A buddy of mine (Mech engineer) had a book called "Ingenious Mechanisms" which was chock-full of goodies like this.
Some really creative minds figure out these contraptions.