09-10-2001 04:17 PM
09-13-2001 02:35 AM
09-13-2001 07:52 PM
01-31-2002 02:47 PM
12-11-2008 09:39 AM
12-16-2008 03:51 PM - edited 12-16-2008 03:52 PM
Hi!
This is what I did to send keyboard commands to another windows program:
//==================================================
#include <windows.h>
#include <utility.h>
#include <ansi_c.h>
#include <cvirte.h>
#include <userint.h>
#define ALT_Key 0x12
#define A_Key 0x41
#define C_Key 0x43
#define E_Key 0x45
#define F_Key 0x46
#define X_Key 0x58
int CVICALLBACK LaunchExternalWinApp (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int app_handle;
switch (event)
{
case EVENT_COMMIT:
LaunchExecutableEx
("notepad.EXE c:\\your_dir\\test.txt",
LE_SHOWNORMAL, &app_handle);
Delay(0.1); //give time for the program to start
// The launched program is focused automatically.
HitKey(ALT_Key);
HitKey(E_Key);
HitKey(A_Key);
HitKey(ALT_Key);
HitKey(E_Key);
HitKey(C_Key);
HitKey(ALT_Key);
HitKey(F_Key);
HitKey(X_Key);
break;
}
return 0;
}
void HitKey(int key_code)
{
/*
// keybd_event() is defined in "Windows.h" header.
NOTE: Even if I use 0 for the "bScanCode" parameter in keybd_event(),
it still works for Windows XP.
*/
// simulate a key press
keybd_event( key_code, 0,
KEYEVENTF_EXTENDEDKEY | 0, 0 );
// simulate a key release
keybd_event( key_code, 0,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
//====================================================
You can find more info at http://www.codeproject.com/KB/system/keyboard.aspx