Use WinAPI SetWindowsHookEx function to set the keyboard hook