Di you want to record this during the user types in an uicontrol - edit field? Or do you want to scan the keys while other programs are active? The later would be a keyboard sniffer and such programs are used for illegal attacks usually. Therefore I will not support a solution.
Note that such data are specific for persons and that you can recognize somebody, while he is using an anonymous internet access point. Microsoft was accused to run such recordings in the beta versions of Win10. In the official releases this feature should have been removed.