//s存放ASC码String,i为你想得到ASCII Code的字符的Index,从0开始 function TForm1.GetASCIICode(s: String; i: Integer): Byte; var p:PChar; begin p:=PChar(s); Result:=Byte(p[i]); end;
不好意思,上面的发错了…… 下面的才是给你的://我只弄成了-,+号模拟左右方向键,模拟Control失败…… //估计对系统键的模拟要用系统钩子了 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, AppEvnts, StdCtrls;type TForm1 = class(TForm) Button1: TButton; ApplicationEvents1: TApplicationEvents; Memo1: TMemo; procedure OnMessage(var Msg: tagMSG; var Handled: Boolean); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } function KeyMapper(var Msg: tagMSG):Boolean; end;var Form1: TForm1;implementation{$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Application.OnMessage:=OnMessage; end;function TForm1.KeyMapper(var Msg: tagMSG): Boolean; begin case Msg.WParam of VK_ADD: Msg.wParam:=VK_RIGHT; VK_SUBTRACT: Msg.wParam:=VK_LEFT; end; result:=false; end;procedure TForm1.OnMessage(var Msg: tagMSG; var Handled: Boolean); begin Handled:=false; case Msg.message of WM_KEYDOWN:Handled:=KeyMapper(Msg); WM_KEYUP:Handled:=KeyMapper(Msg); WM_CHAR:Handled:=KeyMapper(Msg); end; end;end.
to Detective(探长) : 谢了,我刚才也试了,模拟Control也失败了,请再帮关注一下,分稍后加。
刚刚加了一个函数 procedure TForm1.SimControl(var Msg: tagMsg); begin Msg.wParam :=VK_CONTROL; PostMessage(Handle, Msg.message, Msg.wParam, Msg.lParam); end;KeyMapper作了相应修改, function TForm1.KeyMapper(var Msg: tagMSG): Boolean; begin case Msg.WParam of VK_ADD: Msg.wParam:=VK_RIGHT; VK_DIVIDE: SimControl(Msg); VK_SUBTRACT: Msg.wParam:=VK_LEFT; end; result:=false; end;还是失败了……
我只要在本系统内能接收到消息就可以了,用Hook不好(何况我不会^O^),关键是如何知道这两键同时按下了,同时按下'+'时不要在edit等中显示,不知如何将'+'当'Ctrl'用,perform可以吗?
function TForm1.GetASCIICode(s: String; i: Integer): Byte;
var
p:PChar;
begin
p:=PChar(s);
Result:=Byte(p[i]);
end;
下面的才是给你的://我只弄成了-,+号模拟左右方向键,模拟Control失败……
//估计对系统键的模拟要用系统钩子了
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AppEvnts, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ApplicationEvents1: TApplicationEvents;
Memo1: TMemo;
procedure OnMessage(var Msg: tagMSG;
var Handled: Boolean);
procedure FormCreate(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
function KeyMapper(var Msg: tagMSG):Boolean;
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:=OnMessage;
end;function TForm1.KeyMapper(var Msg: tagMSG): Boolean;
begin
case Msg.WParam of
VK_ADD: Msg.wParam:=VK_RIGHT;
VK_SUBTRACT: Msg.wParam:=VK_LEFT;
end;
result:=false;
end;procedure TForm1.OnMessage(var Msg: tagMSG; var Handled: Boolean);
begin
Handled:=false;
case Msg.message of
WM_KEYDOWN:Handled:=KeyMapper(Msg);
WM_KEYUP:Handled:=KeyMapper(Msg);
WM_CHAR:Handled:=KeyMapper(Msg);
end;
end;end.
谢了,我刚才也试了,模拟Control也失败了,请再帮关注一下,分稍后加。
procedure TForm1.SimControl(var Msg: tagMsg);
begin
Msg.wParam :=VK_CONTROL;
PostMessage(Handle, Msg.message, Msg.wParam, Msg.lParam);
end;KeyMapper作了相应修改,
function TForm1.KeyMapper(var Msg: tagMSG): Boolean;
begin
case Msg.WParam of
VK_ADD: Msg.wParam:=VK_RIGHT;
VK_DIVIDE: SimControl(Msg);
VK_SUBTRACT: Msg.wParam:=VK_LEFT;
end;
result:=false;
end;还是失败了……