use Win32::GuiTest qw(:ALL); until ($is_pressed){ $is_pressed = IsKeyPressed("ESC"); } #### $is_pressed = IsKeyPressed("ESC");