Better threshold calculation
Keyboard function proto