Added key grabber on C++ side. Refactored some repeating code.