Cleaning up the dispatch code some more. Apart from less messy code, this allows keybpard-modified mouse events and adds some useful utilities.