Cocoa: Complete and refactor keyboard handling
Merge branch 'cocoa'