外部程序调用(100分)

  • 主题发起人 主题发起人 Magic
  • 开始时间 开始时间
M

Magic

Unregistered / Unconfirmed
GUEST, unregistred user!
; WIN程序调用WIN程序,可通过PostMessage控制,但如果调用一
DOS程序,而PostMessage(HWnd, WM_KEYDOWN, VK_ESCAPE, 0)则
不起作用。
我想通过模拟键盘输入控制DOS程序该如何做?向各位大虾求教。
 
winexec('copy a.txt b.txt',sw_shownormal);
 
g
DOS程序恐怕不支持吧?

BTW:小天,你在说什么?
 
支持DOS的,我试过的
 
DOS程序支持windows消息?
 
当然不支持消息,我指的是用这种方法调用外部命令,即DOS命令,
别用消息了
 
用xxx.exe < aaa.txt的方式可以输入需要的内容.
 
cytown: 你说的只能自动完成输入,并不能模拟手工的实时交互.
 
应该是用WriteConsoleInput模拟键盘输入给dos程序.
 
eyes:能讲一讲吗?
 
例如, 发送'A':
var
rec: TInputRecord;
n: Cardinal;
begin
rec.EventType := KEY_EVENT;
rec.Event.KeyEvent.bKeyDown := true;
rec.Event.KeyEvent.wRepeatCount := 1;
rec. .....
rec.Event.KeyEvent.AsciiChar := 'A'
writeconsoleinput(getstdhandle(STD_INPUT_HANDLE), rec, length(x), n);
end;
 
1.这个TInputRecord是哪里来的?
2.最后结果是发给哪个DOS窗口了呢?
 
1. Windows.pas中定义的
2. 发往当前active的dos窗.
 
1. D5的windows.pas ?
 
1. 对.
如果没有下面是声明:
PKeyEventRecord = ^TKeyEventRecord;
{$EXTERNALSYM _KEY_EVENT_RECORD}
_KEY_EVENT_RECORD = packed record
bKeyDown: BOOL;
wRepeatCount: Word;
wVirtualKeyCode: Word;
wVirtualScanCode: Word;
case Integer of
0: (
UnicodeChar: WCHAR;
dwControlKeyState: DWORD);
1: (
AsciiChar: CHAR);
end;
TKeyEventRecord = _KEY_EVENT_RECORD;
{$EXTERNALSYM KEY_EVENT_RECORD}
KEY_EVENT_RECORD = _KEY_EVENT_RECORD;

PMouseEventRecord = ^TMouseEventRecord;
{$EXTERNALSYM _MOUSE_EVENT_RECORD}
_MOUSE_EVENT_RECORD = packed record
dwMousePosition: TCoord;
dwButtonState: DWORD;
dwControlKeyState: DWORD;
dwEventFlags: DWORD;
end;
TMouseEventRecord = _MOUSE_EVENT_RECORD;
{$EXTERNALSYM MOUSE_EVENT_RECORD}
MOUSE_EVENT_RECORD = _MOUSE_EVENT_RECORD;

PWindowBufferSizeRecord = ^TWindowBufferSizeRecord;
{$EXTERNALSYM _WINDOW_BUFFER_SIZE_RECORD}
_WINDOW_BUFFER_SIZE_RECORD = packed record
dwSize: TCoord;
end;
TWindowBufferSizeRecord = _WINDOW_BUFFER_SIZE_RECORD;
{$EXTERNALSYM WINDOW_BUFFER_SIZE_RECORD}
WINDOW_BUFFER_SIZE_RECORD = _WINDOW_BUFFER_SIZE_RECORD;

PMenuEventRecord = ^TMenuEventRecord;
{$EXTERNALSYM _MENU_EVENT_RECORD}
_MENU_EVENT_RECORD = packed record
dwCommandId: UINT;
end;
TMenuEventRecord = _MENU_EVENT_RECORD;
{$EXTERNALSYM MENU_EVENT_RECORD}
MENU_EVENT_RECORD = _MENU_EVENT_RECORD;

PFocusEventRecord = ^TFocusEventRecord;
{$EXTERNALSYM _FOCUS_EVENT_RECORD}
_FOCUS_EVENT_RECORD = packed record
bSetFocus: BOOL;
end;
TFocusEventRecord = _FOCUS_EVENT_RECORD;
{$EXTERNALSYM FOCUS_EVENT_RECORD}
FOCUS_EVENT_RECORD = _FOCUS_EVENT_RECORD;

PInputRecord = ^TInputRecord;
{$EXTERNALSYM _INPUT_RECORD}
_INPUT_RECORD = record
EventType: Word;
Reserved: Word;
Event: Record case Integer of
0: (KeyEvent: TKeyEventRecord);
1: (MouseEvent: TMouseEventRecord);
2: (WindowBufferSizeEvent: TWindowBufferSizeRecord);
3: (MenuEvent: TMenuEventRecord);
4: (FocusEvent: TFocusEventRecord);
end;
end;
TInputRecord = _INPUT_RECORD;
{$EXTERNALSYM INPUT_RECORD}
INPUT_RECORD = _INPUT_RECORD;

{$EXTERNALSYM WriteConsoleInput}
function WriteConsoleInput(hConsoleInput: THandle; const lpBuffer: TInputRecord;
nLength: DWORD; var lpNumberOfEventsWritten: DWORD): BOOL; stdcall;

kernel32 = 'kernel32.dll';

function WriteConsoleInput; external kernel32 name 'WriteConsoleInputA';
 
eyes,你能否写详细一些,what is length(x) and n?
 
eyes,你能否写详细一些,what is length(x) and n?
can you make a example?
such as dos program need press 'Enter' to go on,
I know dos program's handle,and How can I setkey to it ?
 
Another_eYes:高手.
 
cAkk:说的不错,我作的是一个模拟DOS交互程序。

其他人讲的远了。
当DOS窗口(或全屏)拥有焦点时,我完全可以做到模拟控制,
否则的话,送不入键值。希望大家能想法解决,或给出一个
'行不通'的有力证明。

谢谢!帮一帮我。
 
后退
顶部