Fix error in key capturing where it loops constantly and the CPU is pinned high