Split scaning code and test code.
Add support for key based scanning.