你们看这样行不??
type
    Box : TComboBox;
    XP : TLabel;
    Ctrl        : TRadioButton;
    Alt         : TRadioButton;
    Shift       : TRadioButton;
    Win         : TRadioButton;var
  RightLabel:Cardinal;
  LeftLabel:Cardinal;procedure TForm1.BoxChange(Sender: TObject);
begin
  if Box.Text='0'   then RightLabel:=$30;
  if Box.Text='1'   then RightLabel:=$31;
  if Box.Text='2'   then RightLabel:=$32;
  if Box.Text='3'   then RightLabel:=$33;
  if Box.Text='4'   then RightLabel:=$34;
  if Box.Text='5'   then RightLabel:=$35;
  if Box.Text='6'   then RightLabel:=$36;
  if Box.Text='7'   then RightLabel:=$37;
  if Box.Text='8'   then RightLabel:=$38;
  if Box.Text='9'   then RightLabel:=$39;
  if Box.Text='Insert' then RightLabel:=$2D;
  if Box.Text='Delete' then RightLabel:=$2E;
  RegHotkey;
end;procedure TForm1.CtrlClick(Sender: TObject);
begin
  LeftLabel:=MOD_CONTROL;
  RegHotkey;
end;procedure TForm1.AltClick(Sender: TObject);
begin
  LeftLabel:=MOD_ALT;
  RegHotkey;
end;procedure TForm1.ShiftClick(Sender: TObject);
begin
  LeftLabel:=MOD_SHIFT;
  RegHotkey;
end;procedure TForm1.WinClick(Sender: TObject);
begin
  LeftLabel:=MOD_WIN;
  RegHotkey;
end;procedure TForm1.ComboSelect(Sender: TObject);
begin
  if Combo.Text =Combo.Items.Strings[0]
  then
    begin
      Ctrl.Checked:=True;
      XP.Caption := 'Ctrl';
      LeftLabel:=MOD_CONTROL;
    end;  if Combo.Text =Combo.Items.Strings[1]
  then
    begin
       Alt.Checked:=True;
       XP.Caption := 'Alt';
       LeftLabel:=MOD_Alt;
    end;  if Combo.Text =Combo.Items.Strings[2]
  then
    begin
      Win.Checked:=True;
      xp.Caption := 'Win';
      LeftLabel:=MOD_Win;
    end;
  if Combo.Text =Combo.Items.Strings[3]
  then
    begin
      Shift.Checked:=True;
      xp.Caption := 'Shift';
      LeftLabel:=MOD_Shift;
    end;  RegHotkey;
end;procedure TForm1.RegHotkey;
begin //注册快捷键
  Short:= GlobalAddAtom('short');
  RegisterHotKey(handle,short,LeftLabel,RightLabel);
end;最后别忘了 globalDeleteatom('short');
这样,用户就可以自己选折快捷键了!!

解决方案 »

  1.   

    if Box.Text='0'   then RightLabel:=$30;
      if Box.Text='1'   then RightLabel:=$31;
      if Box.Text='2'   then RightLabel:=$32;
      if Box.Text='3'   then RightLabel:=$33;
      if Box.Text='4'   then RightLabel:=$34;
      if Box.Text='5'   then RightLabel:=$35;
      if Box.Text='6'   then RightLabel:=$36;
      if Box.Text='7'   then RightLabel:=$37;
      if Box.Text='8'   then RightLabel:=$38;
      if Box.Text='9'   then RightLabel:=$39;
      if Box.Text='Insert' then RightLabel:=$2D;
      if Box.Text='Delete' then RightLabel:=$2E;我有个疑问,$34,$35....这写些是什么东东?16进制?而且如果用户设置的都不在0...9之间,而是键盘上的任何键该怎么办?难道要建立所有键的对应表?
      

  2.   

    感谢大家的帮助,但只有budded的回答与我问的比较相近,可能大家还不理解我的意思。
    以下是我自己写的代码,大家看看,再帮帮我。procedure TForm1.gethotkey;
    var modifiers,keys,hotkey,temp:string; i:integer; 
        modifierss,virkey:Candinal;
    begin
     hotkey:=shortcuttotext(form1.HotKey1.hotkey);
     for i:=length(hotkey) downto 1 do
      temp:=temp+hotkey[i];
     modifiers:=copy(temp,pos('+',temp)+1,length(temp));
     keys:=copy(temp,1,pos('+',temp)-1);
     temp:='';
     for i:=length(modifiers) downto 1 do
      temp:=temp+modifiers[i];
     modifiers:=temp;
     temp:='';
     for i:=length(keys) downto 1 do
      temp:=temp+keys[i];
     form1.keys:=temp;
     temp:='';
     //以上就先从hotkey1控件中获得了热键(是String类型的,比如'Ctrl+A');再分解成 'Ctrl'和'A',分别付给modifiers,和keys
     
    if modifiers='Ctrl' then modifierss:=MOD_CONTROL
      else if modifiers='Alt' then modifierss:=MOD_ALT
       else if modifiers='Shift' then modifierss:=MOD_SHIFT
        else if modifiers='Ctrl+Alt' then modifierss:=MOD_CONTROL+MOD_ALT
         else if modifiers='Ctrl+Shift' then modifierss:=MOD_CONTROL+MOD_SHIFT
          else if modifiers='Alt+Shift' then modifierss:=MOD_ALT+MOD_SHIFT
           else if modifiers='Ctrl+Alt+Shift' then modifierss:=MOD_CONTROL+MOD_ALT+MOD_SHIFT;  
    //判断modifiers的值,在对modifierss的值进行设定.//那么,怎么通过判断keys的值,对相应的Virkey付值呢? 
           
    end;
      

  3.   

    if key='F1' then result:=112; if key='0' then result:=$30;
     if key='F2' then result:=113;  if key='1' then result:=$31;
     if key='F3' then result:=114;  if key='2' then result:=$32;
     if key='F4' then result:=115;  if key='3' then result:=$33;
     if key='F5' then result:=116;  if key='4' then result:=$34;
     if key='F6' then result:=117;  if key='5' then result:=$35;
     if key='F7' then result:=118;  if key='6' then result:=$36;
     if key='F8' then result:=119;  if key='7' then result:=$37;
     if key='F9' then result:=120;  if key='8' then result:=$38;
     if key='F10' then result:=121; if key='9' then result:=$39;
     if key='F11' then result:=122;
     if key='F12' then result:=123;  if key='A' then result:=$41;
     if key='B' then result:=$42;
     if key='C' then result:=$43;
     if key='D' then result:=$44;
     if key='E' then result:=$45;
     if key='F' then result:=$46;
     if key='G' then result:=$47;
     if key='H' then result:=$48;
     if key='I' then result:=$49;
     if key='J' then result:=$4A;
     if key='K' then result:=$4B;
     if key='L' then result:=$4C;
     if key='M' then result:=$4D;
     if key='N' then result:=$4E;
     if key='O' then result:=$4F;
     if key='P' then result:=$50;
     if key='Q' then result:=$51;
     if key='R' then result:=$52;
     if key='S' then result:=$53;
     if key='T' then result:=$54;
     if key='U' then result:=$55;
     if key='V' then result:=$56;
     if key='W' then result:=$57;
     if key='X' then result:=$58;
     if key='Y' then result:=$59;
     if key='Z' then result:=$5A; if key='-' then result:=$2D;
     if key='=' then result:=$3D;
     if key='\' then result:=$5C;
     if key='Pause' then result:=144;
     if key='Ins'then result:=$2D; 
     if key='Num Del'then result:=$2E;
     if key='Home'then result:=$24;
     if key='End'then result:=$23;
     if key='Left'then result:=37;
     if key='Right'then result:=39;
     if key='Up'then result:=38;
     if key='Down'then result:=40;
     if key='Num*' then result:=$2A;以上是十六进制的键盘表
    当然你也可以用 VK_??
    哎,我才一个三角,多给点分吧??
      

  4.   

    你在研究研究  热键  的源代码:
    unit Unit1;interfaceuses
      Windows, Messages,Menus, SysUtils, Variants,shellapi, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons,collireg,ras, ImgList, XPMenu, ColListb, Grids,
      ValEdit, ComCtrls,extctrls,
         registry, XP_Form, XP_Button, XP_CheckBox, XP_GroupBox, FavoritesMenu;const wm_baricon=wm_user+200;
    type
      TForm1 = class(TForm)
        ColumnListBox1: TColumnListBox;
        PageControl1: TPageControl;
        TabSheet1: TTabSheet;
        Label1: TLabel;
        Label2: TLabel;
        SpeedButton1: TSpeedButton;
        SpeedButton2: TSpeedButton;
        HotKey1: THotKey;
        ComboBox1: TComboBox;
        XP_Button1: TXP_Button;
        XP_Button2: TXP_Button;
        XP_Button3: TXP_Button;
        TabSheet2: TTabSheet;
        XP_Button4: TXP_Button;
        XP_Button5: TXP_Button;
        XP_Button6: TXP_Button;
        XP_Button7: TXP_Button;
        XP_CheckBox1: TXP_CheckBox;
        TabSheet3: TTabSheet;
        OpenDialog1: TOpenDialog;
        PopupMenu1: TPopupMenu;
        N1: TMenuItem;
        N3: TMenuItem;
        N4: TMenuItem;
        XPMenu1: TXPMenu;
        ColorDialog1: TColorDialog;
        FontDialog1: TFontDialog;
        XP_Form1: TXP_Form;
        Label4: TLabel;
        Label5: TLabel;
        Label3: TLabel;
        FavoritesMenu1: TFavoritesMenu;
        ImageList1: TImageList;
        PopupMenu2: TPopupMenu;
        N2: TMenuItem;
        N5: TMenuItem;
        procedure SpeedButton1Click(Sender: TObject);
        function findkey(var str:string): integer;
        function findstr(var str:string): integer;
        function delicon:boolean;
        procedure FormCreate(Sender: TObject);
        procedure saveandreg;
      //  procedure wmsyscommand(var message:tmessage);
      //  message wm_syscommand;
        procedure wmbaricon(var message:tmessage);
        message wm_baricon;
        procedure minimize(Sender: TObject);
        procedure N4Click(Sender: TObject);
        procedure N1Click(Sender: TObject);
        procedure savetofile;
        procedure getfromfile;
        procedure CheckBox2Click(Sender: TObject);
        procedure unregister( i:integer);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure XP_Button1Click(Sender: TObject);
        procedure XP_Button2Click(Sender: TObject);
        procedure XP_Button3Click(Sender: TObject);
        procedure XP_Button4Click(Sender: TObject);
        procedure XP_Button6Click(Sender: TObject);
        procedure XP_Button5Click(Sender: TObject);
        procedure XP_Button7Click(Sender: TObject);
        procedure Label5MouseLeave(Sender: TObject);
        procedure Label5MouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
        procedure Label5Click(Sender: TObject);
        procedure loadphonebook;
        procedure FormShow(Sender: TObject);
        procedure SpeedButton2Click(Sender: TObject);
        procedure FavoritesMenu1UrlClick(Sender: TObject; Url: String);
        procedure execute(var p:integer);
      private
       // id:Integer;
        s:string;
        id:array[0..255] of integer;
        connect:tlistbox;
         procedure WMHotKey(var Msg : Tmessage); message WM_HOTKEY;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    {$R *.dfm}
    procedure tform1.execute(var p:integer);
    var OSVI:OSVERSIONINFO;
    var j:integer;
    var str:string;
    begin
    OSVI.dwOSversioninfoSize:=Sizeof(OSVERSIONINFO);
    GetVersionEx(OSVI);
    str:='-d '+pchar(ColumnListBox1.ColumnItems[p,1]);
    for j:=0 to connect.Count-1 do
      begin
        if (ColumnListBox1.ColumnItems[p,1]=connect.Items.Strings[j]) and
           (osvi.dwPlatformId = VER_PLATFORM_WIN32_NT)  then
           shellexecute(0,'open','rasphone',pchar(str),nil,sw_normal);
        if (ColumnListBox1.ColumnItems[p,1]=connect.Items.Strings[j]) and
           (osvi.dwPlatformId <>VER_PLATFORM_WIN32_NT)  then
          // shellexecute(0,'open','rasphone',pchar(str),nil,sw_normal);
          //winexec('rundll32.exe '+pchar(str),9)
          shellexecute(0,'open','rundll32.exe','rnaui.dll,RnaDial',nil,sw_normal);
      end;
      if ColumnListBox1.ColumnItems[p,1]='资源管理器' then
      shellexecute(0,'open','explorer.exe',nil,nil,sw_normal);
      if ColumnListBox1.ColumnItems[p,1]='记事本' then
      shellexecute(0,'open','notepad',nil,nil,sw_normal);
      if columnlistbox1.ColumnItems[p,1]='注册表' then
      shellexecute(0,'open','regedit',nil,nil,sw_normal);
      if columnlistbox1.ColumnItems[p,1]='计算器' then
      shellexecute(0,'open','calc',nil,nil,sw_normal);
      if columnlistbox1.ColumnItems[p,1]='控制面板' then
      ShellExecute(0, 'open', 'rundll32.exe', 'shell32.dll,Control_RunDLL ' ,nil,sw_normal)
      else
      shellexecute(0,'open',pchar(ColumnListBox1.ColumnItems[p,1]),nil,nil,sw_normal);
    end;
    procedure tform1.loadphonebook;
    var
        Entries  : array [0..15] of TRASENTRYNAME;
        cb       : DWORD;
        cEntries : DWORD;
        dwRet    : DWORD;
        Buf      : array [0..127] of char;
        I        : Integer;
    begin
     connect:=tlistbox.Create(form1);
     connect.Parent:=form1;
     FillChar(Entries, SizeOf(Entries), 0);
     Entries[0].dwSize := SizeOf(TRASENTRYNAME);
     cb := SizeOf(Entries);
     cEntries := 0;
     dwRet := RasEnumEntriesA(NIL, NIL, @Entries[0], @cb, @cEntries);
     for I := 0 to cEntries - 1 do
     begin
     connect.Items.Add(Entries[I].szEntryName);
     combobox1.Items.Add(Entries[I].szEntryName);
     end;
     connect.Visible:=false;
     end;procedure tform1.unregister( i:integer);
    begin
      UnRegisterHotKey(handle,id[i]);// 释放你应用程序定义的热键
      GlobalDeleteAtom(id[i]);//
    end;procedure tform1.minimize(Sender: TObject);
    var lpdata:tnotifyicondata;
    begin
    {} lpdata.cbSize:=sizeof(lpdata);
     lpdata.Wnd:=form1.Handle;
     lpdata.uID:=1;
     lpdata.uFlags:=nif_icon or nif_message or nif_tip;
     lpdata.uCallbackMessage:=wm_baricon;
     lpdata.hIcon:=application.Icon.Handle;
     lpdata.szTip:='热键';
     shell_notifyicon(nim_add,@lpdata);
     showwindow(application.Handle,sw_hide);  
    end;procedure tform1.savetofile;
    var
      F: TextFile;
      fhandle,i:integer;
    begin
       if  fileexists('c:\hotkey.dat') then
        begin
         deletefile('c:\hotkey.dat');
        end ;
        fhandle:=filecreate('c:\hotkey.dat');
        fileclose(fhandle); 
        AssignFile(f, 'c:\hotkey.dat');
        append(f);
        for i:=0 to columnlistbox1.count-1  do
        begin
        writeln(f,ColumnListBox1.ColumnItems[i,0]);
        writeln(f,ColumnListBox1.ColumnItems[i,1]);
        end;
        CloseFile(F);
    end;procedure tform1.getfromfile;
    var flist:tlistbox;
    var i:integer;
    begin
      flist:=tlistbox.Create(self);
      flist.Parent:=form1 ;
      flist.Visible:=false;
      if fileexists('c:\hotkey.dat') then
      begin
      flist.Items.LoadFromFile('c:\hotkey.dat');
      if flist.Items.Count-1<>-1 then
      begin
       for i:=0 to (flist.Items.Count-1) div 2 do
        begin
         with ColumnListBox1.ListBoxItems.Add do
           begin
            Strings.Add(flist.Items.Strings[2*i]);
            Strings.Add(flist.Items.Strings[2*i+1]);
           end;
        end;
      end;
      end;end;function tform1.delicon:boolean;
    var lpdata:tnotifyicondata;
    begin
     lpdata.cbSize:=sizeof(lpdata);
     lpdata.Wnd:=form1.Handle;
     lpdata.uID:=1;
     shell_notifyicon(nim_delete,@lpdata);
     result:=true;
    end;{procedure tform1.wmsyscommand(var message:tmessage);
    var lpdata:tnotifyicondata;
    begin
     if message.WParam=sc_icon then
     begin
     lpdata.cbSize:=sizeof(lpdata);
     lpdata.Wnd:=form1.Handle;
     lpdata.uID:=1;
     lpdata.uFlags:=nif_icon or nif_message or nif_tip;
     lpdata.uCallbackMessage:=wm_baricon;
     lpdata.hIcon:=application.Icon.Handle;
     lpdata.szTip:='热键';
     shell_notifyicon(nim_add,@lpdata);
     form1.Visible:=false;
     showwindow(application.Handle,sw_hide);
     end
     else
     defwindowproc(application.Handle,message.Msg,message.WParam,message.LParam);
    end;    }
      

  5.   

    procedure tform1.wmbaricon(var message: tmessage);
    //var lpdata:tnotifyicondata;
    var mousepoint:tpoint;
    begin
     if message.lParam=WM_LBUTTONUP then
     begin
       showwindow(application.Handle,sw_show);
       application.Restore;
       form1.Visible:=true;
      delicon; end;
     if message.lParam=wm_rbuttondown then
     begin
      getcursorpos(mousepoint);
      form1.PopupMenu1.Popup(mousepoint.X,mousepoint.y);
     end;
    end;   procedure TForm1.WMHotKey (var Msg : Tmessage);
    var key,p,i,j:integer;
    var str,ps:string;
    begin
     for i:=0to columnlistbox1.Count-1 do begin
       s:=ColumnListBox1.ColumnItems[i,0] ;
       key:=findkey(s);// showmessage(inttostr(key));
    if (msg.LParamHi=key ) and (msg.lparamlo=MOD_shift )then
    begin
      for p:=0 to columnlistbox1.Count-1 do
      begin
        ps:=ColumnListBox1.ColumnItems[p,0];
        if  (pos('Shift',ColumnListBox1.ColumnItems[p,0])<>0) and
            (pos('Alt',ColumnListBox1.ColumnItems[p,0])=0) and
            (pos('Ctrl',ColumnListBox1.ColumnItems[p,0])=0)and
            (findkey(ps)=key) then
             form1.execute(p);
       end;
    break;
    end;
    if (msg.LParamHi=key ) and (msg.lparamlo=MOD_control )then
    begin
    for p:=0 to columnlistbox1.Count-1 do
      begin
         ps:=ColumnListBox1.ColumnItems[p,0];
        if (pos('Ctrl',ColumnListBox1.ColumnItems[p,0])<>0) and
           (pos('Alt',ColumnListBox1.ColumnItems[p,0])=0) and
           (pos('Shift',ColumnListBox1.ColumnItems[p,0])=0)and
           (findkey(ps)=key)then
           form1.execute(p);
      end;
    break;
    end;
    if (msg.LParamHi=key ) and (msg.lparamlo=MOD_alt )then
    begin
    for p:=0 to columnlistbox1.Count-1 do
      begin
        ps:=ColumnListBox1.ColumnItems[p,0];
        if (pos('Alt',ColumnListBox1.ColumnItems[p,0])<>0) and
           (pos('Shift',ColumnListBox1.ColumnItems[p,0])=0) and
           (pos('Ctrl',ColumnListBox1.ColumnItems[p,0])=0)and
           (findkey(ps)=key)then
           form1.execute(p);
      end;
    break;
    end;
    if (msg.LParamHi=key ) and (msg.lparamlo=MOD_alt+mod_control )then
    begin
    for p:=0 to columnlistbox1.Count-1 do
      begin
         ps:=ColumnListBox1.ColumnItems[p,0];
        if (pos('Ctrl',ColumnListBox1.ColumnItems[p,0])<>0) and
         (pos('Alt',ColumnListBox1.ColumnItems[p,0])<>0) and
         (pos('Shift',ColumnListBox1.ColumnItems[p,0])=0)and
         (findkey(ps)=key)then
        form1.execute(p);
      end;
    break;
    end;
    if (msg.LParamHi=key ) and (msg.lparamlo=MOD_alt+mod_shift )then
    begin
    for p:=0 to columnlistbox1.Count-1 do
      begin
        ps:=ColumnListBox1.ColumnItems[p,0];
        if (pos('Shift',ColumnListBox1.ColumnItems[p,0])<>0) and
           (pos('Alt',ColumnListBox1.ColumnItems[p,0])<>0)and
           (pos('Ctrl',ColumnListBox1.ColumnItems[p,0])=0)and
           (findkey(ps)=key)then
        form1.execute(p);
      end;
    break;
    end;if (msg.LParamHi=key ) and (msg.lparamlo=MOD_control+mod_shift )then
    begin
    for p:=0 to columnlistbox1.Count-1 do
      begin
         ps:=ColumnListBox1.ColumnItems[p,0];
        if (pos('Shift',ColumnListBox1.ColumnItems[p,0])<>0) and
         (pos('Ctrl',ColumnListBox1.ColumnItems[p,0])<>0) and
         (pos('Alt',ColumnListBox1.ColumnItems[p,0])=0)and
           (findkey(ps)=key)then
        form1.execute(p);
      end;
    break;
    end;
    if (msg.LParamHi=key ) and (msg.lparamlo=MOD_shift+mod_alt+mod_control)then
    begin
    for p:=0 to columnlistbox1.Count-1 do
      begin
         ps:=ColumnListBox1.ColumnItems[p,0];
        if ((pos('Shift',ColumnListBox1.ColumnItems[p,0])<>0) and
         (pos('Alt',ColumnListBox1.ColumnItems[p,0])<>0) and
         (pos('Ctrl',ColumnListBox1.ColumnItems[p,0])<>0))and
           (findkey(ps)=key) then
        form1.execute(p);
      end;
    break;
    end;end;
    end;{ctrl=1,shift=2,alt=4}
    function tform1.findstr(var str:string):integer;
    var flag:integer;
    begin
    flag:=0;
    if pos('Ctrl',str)<>0 then  flag:=flag+1;
    if pos('Shift',str)<>0 then flag:=flag+2;
    if pos('Alt',str)<>0 then flag:=flag+4;
    if flag=1 then {showmessage('ctrl');}result:=1;
    if flag=2 then {showmessage('shift');} result:=2;
    if flag=4 then {showmessage('alt');} result:=4;
    if flag=3 then {showmessage('ctrl,shift');}result:=3;
    if flag=5 then {showmessage('ctrl,alt');}result:=5;
    if flag=6 then {showmessage('shift,alt');}result:=6 ;
    if flag=7 then {showmessage('ctrl,alt,shift')}result:=7;
    //if flag=0 then showmessage('character');
    end;