键盘输入?(10分)

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

MaxWoods

Unregistered / Unconfirmed
GUEST, unregistred user!
在C中有一个getch();函数,用来等待一个键盘输入;在Delphi中与之等介的函数是什么?
 
Keydown事件
 
Pipi. (2002-5-7 19:41:00)
下面的一段代码仅仅用来等待键盘事件:

uses windows;

VAR
h:THandle;
buf:INPUT_RECORD;
n:DWORD;

h:=GetStdHandle(STD_INPUT_HANDLE);
while true do
begin
ReadConsoleInput(h,buf,1,n);
if (n=1) and (buf.EventType=KEY_EVENT) then
break;
Sleep(100);
end;

//注意 h 不必CloseHandle

 
program Thread3;

{$APPTYPE CONSOLE}

uses SysUtils,Windows;

var hThrd1,hThrd2:Cardinal;exitCode1,exitCode2,threadID:LongWord;
i:Cardinal;

function ThreadFunc(p:Pointer):LongWord;
begin
Sleep(Cardinal(p)*1000*2);
Write(Cardinal(p));
Write(#$D#$A);
Result:=Cardinal(p)*10;
end;

begin

exitCode1:=0;
exitCode2:=0;

i:=Cardinal(1);
hThrd1:=CreateThread(nil,0,@ThreadFunc,@i,0,threadID);
if(hThrd1<>0) then Write('Thread 1 launched'#$D#$A);
i:=Cardinal(2);
hThrd2:=CreateThread(nil,0,@ThreadFunc,@i,0,threadID);
if(hThrd2<>0) then Write('Thread 2 launched'#$D#$A);
repeat
//这里要等待键盘输入,怎么写?
GetExitCodeThread(hThrd1,exitCode1);
GetExitCodeThread(hThrd2,exitCode2);
until ((exitCode1<>STILL_ACTIVE) and (exitCode2<>STILL_ACTIVE));

CloseHandle(hThrd1);
CloseHandle(hThrd2);

Write('Thread 1 returned ',exitCode1,#$D#$A);
Write('Thread 2 returned ',exitCode2,#$D#$A);

ExitCode:=0;

end.

还有,上面程序运行后,Thread1,Thread2总里返回0,但线程参数不是0,为什么?
 
后退
顶部