xuanloc optimised code for digit pressed handling