A
arm
Unregistered / Unconfirmed
GUEST, unregistred user!
unit doskey;
interface
uses
Windows, Messages,stdctrls,SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
Tdoskey = class(TComponent)
private
factive:boolean;
fesckey:boolean;
fenterkey:boolean;
fupdownkey:boolean;
ff2key: boolean;
flastwasedit:boolean;
fownerkeypress:tkeyevent;
protected
procedure newkeydown(sender:tobject;var key :word;shift:tshiftstate);
public
constructor create(aowner:tcomponent);override;
published
property active :boolean read factive write factive default false;
property esckey :boolean read fesckey write fesckey default true;
property enterkey:boolean read fenterkey write fenterkey default true;
property updownkey :boolean read fupdownkey write fupdownkey default true;
property f2:boolean read ff2key write ff2key default true;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [Tdoskey]);
end;
{ Tdoskey }
{ Tdoskey }
constructor Tdoskey.create(aowner: tcomponent);
var
count:integer;
begin
for count:=0 to aowner.ComponentCount-1 do
if aowner.Components[count] is TDOSKEY then
raise EInvalidOperation.create('only one control can on one form');
factive:=false;
fesckey:=true;fenterkey:=true;
fupdownkey:=true;ff2key:=true;
(aowner as tform).keypreview:=true;
(aowner as tform).onkeydown:=newkeydown;
inherited create(aowner);
end;
procedure Tdoskey.newkeydown(sender: tobject; var key: word;
shift: tshiftstate);
var
count,m:integer;
begin
if factive then
begin
flastwasedit:=(owner as tform).activecontrol is tcustomedit;
if flastwasedit then
begin
if ((key=vk_down) and (fupdownkey=true)) or ((key=vk_return) and (fenterkey=true))then
(owner as tform).perform(Wm_nextdlgctl,0,0);
if ((key=vk_up) and (fupdownkey=true)) then
(owner as tform).perform(Wm_nextdlgctl,1,0);
if ((key=27) and (fesckey=true)) then
begin
for count:=0 to owner.ComponentCount-1 do
if owner.Components[count] is Tcustomedit then
begin
m:=count;
break;
end;
for count:=0 to owner.ComponentCount-1 do
if owner.Components[count] is Tcustomedit then
(owner.Components[count] as tcustomedit).clear;
if owner.Components[m] is Tcustomedit then
(owner.Components[m] as tcustomedit).setfocus;
end;
if ((key=vk_f2) and (ff2key=true)) then
if (owner as tform).activecontrol is Tcustomedit then
((owner as tform).activecontrol as tcustomedit).clear;
end;
if assigned(fownerkeypress) then
fownerkeypress(sender,key,shift);
end;
end;
end.
interface
uses
Windows, Messages,stdctrls,SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
Tdoskey = class(TComponent)
private
factive:boolean;
fesckey:boolean;
fenterkey:boolean;
fupdownkey:boolean;
ff2key: boolean;
flastwasedit:boolean;
fownerkeypress:tkeyevent;
protected
procedure newkeydown(sender:tobject;var key :word;shift:tshiftstate);
public
constructor create(aowner:tcomponent);override;
published
property active :boolean read factive write factive default false;
property esckey :boolean read fesckey write fesckey default true;
property enterkey:boolean read fenterkey write fenterkey default true;
property updownkey :boolean read fupdownkey write fupdownkey default true;
property f2:boolean read ff2key write ff2key default true;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [Tdoskey]);
end;
{ Tdoskey }
{ Tdoskey }
constructor Tdoskey.create(aowner: tcomponent);
var
count:integer;
begin
for count:=0 to aowner.ComponentCount-1 do
if aowner.Components[count] is TDOSKEY then
raise EInvalidOperation.create('only one control can on one form');
factive:=false;
fesckey:=true;fenterkey:=true;
fupdownkey:=true;ff2key:=true;
(aowner as tform).keypreview:=true;
(aowner as tform).onkeydown:=newkeydown;
inherited create(aowner);
end;
procedure Tdoskey.newkeydown(sender: tobject; var key: word;
shift: tshiftstate);
var
count,m:integer;
begin
if factive then
begin
flastwasedit:=(owner as tform).activecontrol is tcustomedit;
if flastwasedit then
begin
if ((key=vk_down) and (fupdownkey=true)) or ((key=vk_return) and (fenterkey=true))then
(owner as tform).perform(Wm_nextdlgctl,0,0);
if ((key=vk_up) and (fupdownkey=true)) then
(owner as tform).perform(Wm_nextdlgctl,1,0);
if ((key=27) and (fesckey=true)) then
begin
for count:=0 to owner.ComponentCount-1 do
if owner.Components[count] is Tcustomedit then
begin
m:=count;
break;
end;
for count:=0 to owner.ComponentCount-1 do
if owner.Components[count] is Tcustomedit then
(owner.Components[count] as tcustomedit).clear;
if owner.Components[m] is Tcustomedit then
(owner.Components[m] as tcustomedit).setfocus;
end;
if ((key=vk_f2) and (ff2key=true)) then
if (owner as tform).activecontrol is Tcustomedit then
((owner as tform).activecontrol as tcustomedit).clear;
end;
if assigned(fownerkeypress) then
fownerkeypress(sender,key,shift);
end;
end;
end.