Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stuffing the keyboard buffer
Message
From
03/06/1999 14:20:23
 
 
To
03/06/1999 14:08:22
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00225979
Message ID:
00226127
Views:
26
>>>>>Does anybody know the correct syntax in VFP to declare and call
>>>>>the "keybd_event" API function?
>>>>>
>>>>>I'm running an external application which when it runs presents the user with a Yes and No button, with the Yes button set as the default. I am trying to automate the execution of this external function as much as possible and want to programmatically press the Enter key to trigger the Yes button and conclude the process.
>>>>
>>>>I think you're going to need to use several API calls to do this, at a minimum, you'll need to know the hWnd of the messagebox so that you can call SetFocus() to point the keyboard focus to the target window, and then issue a keybd_event, since keybd_event doesn't set the context that the keystroke is processed in.
>>>
>>>
>>>I have the hWnd of the called function because I'm running the function via
>>>CreateProcess(). The function has the keyboard focus just after I open it so I'm pretty sure my simulated keyboard event will hit it. I just need the syntax of the declare dll statement and the syntax to call the function.
>>
>>Actually, you have the ProcessID and Process Handle coming back from the PROCESSINFO structure, neither is an hWnd. Regardless, the following declare will work for keybd_event where you have the proper window in focus. Note: I used SHORTs even though it's a BYTE value; only the low-order byte is considered, so keep the values below 256:
>>
>>
DECLARE keybd_event IN USER32.DLL ;
>>   SHORT bVk, ;
>>   SHORT bScan, ;
>>   INTEGER dwFlags, ;
>>   INTEGER dwExtraInfo
>>#DEFINE VK_RETURN 0xOD
>>=keybd_event(VK_RETURN,0,0,0)  && return was pressed
>>
>
>Thanks Ed.
>I tried your suggestion, however I'm getting a compile time error:
> "Function name is missing )."
>on the line containing the =keybd_event(VK_RETURN,0,0,0) statement.
>I'm not sure but I have a hunch it may be related to the #define statement.

Yeah, it looks like the 0x0D got typed in as 0xOD (the second "0" got typed in as an uppercase "O"). Sorry about that.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform