if you in Windows there is a second way:
for (i=0; i<n; i++){ //if Enter key press down if (GetKeyState(VK_RETURN) & 0x8000){ //wait for Enter press up while (GetKeyState(VK_RETURN) & 0x8000) {} dosomething(); } }