안녕하세요? 이종극입니다.
키보드제어에 대하여 아래에 질문을 올렸지만...
다음의 코드를 보시고 문제점을 찾아주시면 고맙겠습니다.
해당프로그램내에서는 키보드의 상태가 정확하게 일치하는데
다중작업시에 문제가 있는것 같군요.
선배님들의 조언을 기다리며...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
//I: Integer;
KeyState: TKeyboardState;
begin
GetKeyboardState(KeyState); //키보드상태 얻기
//for I := Low(KeyState) to High(KeyState) do
// KeyState[I] := 0;
// 1 = 대문자, 0 = 소문자
if KeyState [VK_CAPITAL] = 1 then
KeyState [VK_CAPITAL] := 0
else KeyState [VK_CAPITAL] := 1;
SetKeyboardState(KeyState); // 변경된 키보드상태 설정
//SendMessage(Handle, WM_KEYDOWN, VK_CAPITAL, 1);
//SendMessage(Handle, WM_KEYUP, VK_CAPITAL, 1);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
KeyState: TKeyboardState;
begin
GetKeyboardState(KeyState);
if KeyState [VK_NUMLOCK] = 1 then
KeyState [VK_NUMLOCK] := 0
else KeyState [VK_NUMLOCK] := 1;
SetKeyboardState(KeyState);
end;
end.
|