如何做一个最最简单的输入法.输入某个指定的字符.例如button一按,便有字显示在某窗口编辑框里.
请给个例子,最好是代码,越简单越好.(不是要编码的那种)

解决方案 »

  1.   

    那得等等啦。我今天试了一下,还没搞完。你该不是要输入到Word之类的其他程序里吧。程序间通讯不好做。哎!为啥就没有可扩展的输入法呢?
      

  2.   

    写了一些代码,Win98下调试过,试试看吧!如果不清楚,我已把它写成文章贴到这个网站上了,你找一下吧。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Clipbrd;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
    Form1: TForm1;
    hHook:integer;
    EventArr:EVENTMSG;implementationfunction HookProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
     var
          c:integer;
    begin
    Result := 0;
    If iCode < 0 then Result := CallNextHookEx(hHook,iCode,WParam,LParam);
     EventArr:=pEventMSG(lParam)^;//通过钩子的Lparam参数,让EventArr得到键盘的消息
    If iCode = HC_ACTION then  //是否钩到东西
      If EventArr.message=wm_keydown then Begin // 看按键是否被按下       c:=lo(EventArr.paramL);//Paraml的低位就是按下的按键的ASCII码
      if c=65 then
      begin  clipboard.Open;//打开剪贴板,清空,设置Format,设置剪贴板内容
      clipboard.Clear;
      clipboard.Formats[CF_text];
      clipboard.setTextbuf(pchar('α')); 
      Clipboard.Close;
      end;
      end;
    end;
    {$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      Button1.Caption:='hook';
      Button2.Caption:='unhook';
      Button2.Enabled:=False;end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      //建立键盘操作消息hook链
      hHook:=SetwindowsHookEx(WH_JOURNALRECORD,HookProc,HInstance,0);
      Button2.Enabled:=True;
      Button1.Enabled:=False;end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      UnHookWindowsHookEx(hHook);//卸钩子
      hHook:=0;
      Button1.Enabled:=True;
      Button2.Enabled:=False;
      end;end.