Code to take input from Keyboard

Hello Again,

I want to write a code that will execute when a key is pressed by the user (for example arrow keys). I have already written the code to be executed but just can't make it to work only when the key is pressed.

I am guessing  Prompt is the one to use but I'm not sure.

Help me out please.

Thanks.
Prompt - DoPrompt creates a window for the user to provide values (variables or strings).

If you want code that responds to a key press (like the down arrow), you will need to write a hook function.
A window hook can, in fact, respond to key presses. But it requires a window and will only receive key presses when the window has keyboard focus.

You can also use GetKeyState(), but you have to poll for the input.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Execute this for a window hook function example:
DisplayHelpTopic "Window Hook Functions"

For a detailed example of a keyboard hook function, look in procedure file for the Scroll Traces package for the code segment that starts with ...

// hook function that handles keyboard events in non-movie mode

Function ScrollTracesKeyboardHook(sh)
    STRUCT WMWinHookStruct &sh


The relevant code segment is attached as a txt file.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
keyboardhook.txt