开发一个触摸浏览器,如何做一个虚拟键盘?(200)

  • 主题发起人 主题发起人 romanzhong
  • 开始时间 开始时间
R

romanzhong

Unregistered / Unconfirmed
GUEST, unregistred user!
用delphi开发一个触摸浏览器。 写了一个模拟键盘, 怎么做到,当打开的网页中,碰到可输入地方的时候,自动弹出已经写好的模拟键盘? 并将模拟键盘的输入值传到可输入框?谢谢!
 
调用windows系统的屏幕键盘好了
 
就用button实现啊。---------------------------矢量图形组件TCADhttp://www.codeidea.com/cn
 
用button已经写了一个键盘软件。 但当用户触摸到打开网页的“可输入框”的时候, 怎样自动弹出键盘软件?
 
我自己写的一个//sndkey32.pas网上应该有unit KeyboardUnit;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,sndkey32, Buttons, ExtCtrls,DefineUnit ;const MaxStrRecs = 78; KeyBroadStr : array[0..MaxStrRecs] of String = ('ESC','F1','F2','F3','F4','F5','F6','F7','F8','F9','F10','F11','F12','PRTSC','BREAK', '`','1','2','3','4','5','6','7','8','9','0','-','=','BACKSPACE', 'TAB','Q','W','E','R','T','Y','U','I','O','P','[',']','/', 'CAPSLOCK','A','S','D','F','G','H','J','K','L',';','''', 'ENTER', 'SHIFT','Z','X','C','V','B','N','M',',','.','/','UP', 'CTRL','ALT','SPACE','DEL','HOME','END','PGUP','PGDN','LEFT','DOWN','RIGHT');type TFrmKeyboard = class(TForm) Btnc_Num: TSpeedButton; SpeedButton17: TSpeedButton; SpeedButton18: TSpeedButton; SpeedButton19: TSpeedButton; SpeedButton20: TSpeedButton; SpeedButton21: TSpeedButton; SpeedButton22: TSpeedButton; SpeedButton23: TSpeedButton; SpeedButton24: TSpeedButton; SpeedButton25: TSpeedButton; SpeedButton26: TSpeedButton; SpeedButton27: TSpeedButton; SpeedButton28: TSpeedButton; SpeedButton29: TSpeedButton; BtnCommand: TSpeedButton; SpeedButton31: TSpeedButton; SpeedButton32: TSpeedButton; SpeedButton33: TSpeedButton; SpeedButton34: TSpeedButton; SpeedButton35: TSpeedButton; SpeedButton36: TSpeedButton; SpeedButton37: TSpeedButton; SpeedButton38: TSpeedButton; SpeedButton39: TSpeedButton; SpeedButton40: TSpeedButton; SpeedButton41: TSpeedButton; SpeedButton42: TSpeedButton; SpeedButton43: TSpeedButton; SpeedButton44: TSpeedButton; SpeedButton45: TSpeedButton; SpeedButton46: TSpeedButton; SpeedButton47: TSpeedButton; SpeedButton48: TSpeedButton; SpeedButton49: TSpeedButton; SpeedButton50: TSpeedButton; SpeedButton51: TSpeedButton; SpeedButton52: TSpeedButton; SpeedButton53: TSpeedButton; SpeedButton54: TSpeedButton; SpeedButton55: TSpeedButton; SpeedButton56: TSpeedButton; SpeedButton58: TSpeedButton; SpeedButton59: TSpeedButton; SpeedButton60: TSpeedButton; SpeedButton61: TSpeedButton; SpeedButton62: TSpeedButton; SpeedButton63: TSpeedButton; SpeedButton64: TSpeedButton; SpeedButton65: TSpeedButton; SpeedButton66: TSpeedButton; SpeedButton67: TSpeedButton; SpeedButton68: TSpeedButton; SpeedButton71: TSpeedButton; SpeedButton72: TSpeedButton; SpeedButton73: TSpeedButton; SpeedButton74: TSpeedButton; SpeedButton77: TSpeedButton; SpeedButton78: TSpeedButton; SpeedButton79: TSpeedButton; Panel1: TPanel; StaticText1: TStaticText; StaticText2: TStaticText; BtnShift: TSpeedButton; btnHide: TSpeedButton; procedure Btnc_NumClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormShow(Sender: TObject); procedure BtnCommandClick(Sender: TObject); procedure btnHideClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } FMsgHandle:THandle; //用于父窗口的窗口句柄 FISNumber:byte; //0 表示可以输入任何字符 1 表示只能输入整数,2表示可以输入小数 procedure SetISNumber(Value:byte); procedure SetMsgHandle(H:THandle); public { Public declarations } WCFoucs:TWinControl; WindowName : PChar; sWHandle:Longint; procedure WMActivate(var Message: TMessage); message WM_ACTIVATE; property MsgHandle:THandle read FMsgHandle write SetMsgHandle; property IsNumber :byte Read FISNumber Write SetISNumber; end;var FrmKeyboard: TFrmKeyboard;implementation{$R *.dfm}procedure TFrmKeyboard.SetMsgHandle(H:THandle);begin FMsgHandle:=H;end;procedure TFrmKeyboard.SetISNumber(Value:byte);var i:Integer; ntag:Integer;begin if Value>2 then exit; FISNumber:=Value; case FISNumber of 0: //0 表示可以输入任何字符 begin for i:=0 to self.ComponentCount-1 do begin if self.Components is TSpeedButton then (self.Components as TSpeedButton).Enabled :=true; end; end; 1: //1 表示只能输入整数 begin SpeedButton44.Down := False; BtnShift.Down :=False; for i:=0 to self.ComponentCount-1 do begin if self.Components is TSpeedButton then begin ntag:= (self.Components as TSpeedButton).Tag ; if (ntag<16) or (ntag >26) then (self.Components as TSpeedButton).Enabled :=false; if ntag in [28,29,55,71,72,71,73,79] then (self.Components as TSpeedButton).Enabled :=true; end; end; //end for end; 2: //2表示可以输入小数 begin SpeedButton44.Down := False; BtnShift.Down :=False; for i:=0 to self.ComponentCount-1 do begin if self.Components is TSpeedButton then begin ntag:= (self.Components as TSpeedButton).Tag ; if (ntag<16) or (ntag >26) then (self.Components as TSpeedButton).Enabled :=false; if ntag in [28,29,55,65,71,72,71,73,79] then (self.Components as TSpeedButton).Enabled :=true; end; end; //end for end; end;end;procedure TFrmKeyboard.WMActivate(var Message: TMessage);begin if (Message.wParamLo = WA_CLICKACTIVE) and (message.lParam<>sWHandle) then begin //得到当前活动窗口的标题 GetWindowText(message.lParam,WindowName,MAX_PATH); end;end;procedure TFrmKeyboard.Btnc_NumClick(Sender: TObject);Var Str:String; iTag:Integer;begin //发送字符 if WindowName=nil then exit; iTag:=(sender as TSpeedButton).Tag ; Str:= KeyBroadStr[iTag] ; if BtnShift.Down then Str:='+'+Str ; {ELSE IF BtnAlt.Down then Str:='%'+Str ELSE IF BtnCtrl.Down then Str:='^'+Str; } AppActivate(WindowName); //设置输入焦点窗口为活动窗口,以便接收消息 SendKeyS(PChar(Str),false);end;procedure TFrmKeyboard.FormCreate(Sender: TObject);begin FISNumber:=0; //分配窗口名称空间 GetMem(WindowName,MAX_PATH); sWHandle:=self.Handle ; Top :=600-self.Height ; Left:=800-self.Width ;end;procedure TFrmKeyboard.FormDestroy(Sender: TObject);begin //释放窗口名称空间 FreeMem(WindowName);end;procedure TFrmKeyboard.FormShow(Sender: TObject);var WHandle:Longint;begin //得到当前最前的窗口句柄 WHandle:=GetForegroundWindow; //得到窗口的标题 GetWindowText(WHandle,WindowName,MAX_PATH); SpeedButton44.Caption :='Caps Lock' +Char(13)+Char(10)+'大小写切换'; BtnShift.Caption :='Shift'+ Char(13)+Char(10)+'第二字符切换'; SpeedButton56.Caption :='Enter'+ Char(13)+Char(10)+'回车'; SpeedButton72.Caption :='Del'+ Char(13)+Char(10)+'删除'; SpeedButton29.Caption :='Backspace'+ Char(13)+Char(10)+'删除'; SpeedButton71.Caption :='Space'+ Char(13)+Char(10)+'空格'; SetWindowPos(Self.Handle, HWND_TOPMOST, self.Left ,Self.Top , self.Width ,self.Height , SWP_NOACTIVATE); ShowWindow(Self.Handle, SW_SHOWNOACTIVATE); if FMsgHandle<>0 then PostMessage(FMsgHandle,FSystemUserMsg, 1,5); end;procedure TFrmKeyboard.BtnCommandClick(Sender: TObject);Var Str:String; iTag:Integer;begin //发送命令码 if WindowName=nil then exit; AppActivate(WindowName); //设置输入焦点窗口为活动窗口,以便接收消息 iTag:=(sender as TSpeedButton).Tag ; Str:= '{'+KeyBroadStr[iTag]+'}' ; {IF BtnCtrl.Down then Str:='^'+Str;} SendKeys(PChar(Str), false);end;procedure TFrmKeyboard.btnHideClick(Sender: TObject);begin Close;end;procedure TFrmKeyboard.FormClose(Sender: TObject; var Action: TCloseAction);begin if FMsgHandle<>0 then PostMessage(FMsgHandle,FSystemUserMsg, 0,5);end;end.
 
看错了,还以为你要软件盘的代码
 
你写了这个软件盘后, 如何在网页的编辑框中自动调出?
 
自己开发的浏览器,应该可以在编辑框获得焦点的时候自动调用软键盘吧?
 
自己开发浏览器, 就是想在编辑框获得焦点的时候自动调用软键盘, 请各位高手赐教!
 
你现在碰到了什么问题?获取焦点时没有onEnter事件?有的话直接在里面调用就是了。
 
后退
顶部