Detect if a Key is Pressed
Keywords: trapkeys iskeydown waitforkey
The following sample code can detect if any key on the keyboard has been pressed:#definefunction GetKeyboardState(buf) sDLLName = StrCat(DirWindows(1), "user32.dll") DLLCall(sDLLName, long:"GetKeyboardState", lpbinary:buf) BinaryEodSet(buf, 256) return buf #endfunction boxopen("","Press any key.") buf1 = binaryalloc(256) before = GetKeyboardState(buf1) buf2=binaryalloc(256) while 1 after = GetKeyboardState(buf2) if BinaryCompare(before, 0, after, 0, 256)==@false then break endwhile binaryfree(buf2) message("","you pressed a key")
Article ID: W15282