我有一Radiobutton 想设置其快捷键为f5,要达到在任何状态下按F5都让RADIOBUTTON
获取焦点,急啊,各位大师帮我啊,最好是完整代码

解决方案 »

  1.   

    用如下方法:
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      id:=GlobalAddAtom('MyHotkey');
      id1:=GlobalAddAtom('MyHotkey1');
      id2:=GlobalAddAtom('MyHotkey2');
      RegisterHotKey(Handle, id, MOD_CONTROL, VK_F1);
      RegisterHotKey(Handle, id1, MOD_CONTROL, VK_F2);
      RegisterHotKey(Handle, id2, MOD_CONTROL, VK_F3);
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      UnregisterHotKey(Handle,ID);
      UnregisterHotKey(Handle,ID1);
      UnregisterHotKey(Handle,ID2);
    end;procedure TForm1.WMHotKey(var Msg: TWMHotKey);
    begin
      if msg.HotKey=ID then
        ShowMessage('Ctrl+F1!')
      else if Msg.HotKey=ID1 then
        ShowMessage('Ctrl+F2!')
      else if Msg.HotKey=ID2 then
        ShowMessage('Ctrl+F3!');
    end;
      

  2.   

    我试了怎么没有反应呢?
      procedure TForm1.FormCreate(Sender: TObject);
    begin
      id:=GlobalAddAtom('112'); //a r 键值
      id1:=GlobalAddAtom('113');
      id2:=GlobalAddAtom('114');
      RegisterHotKey(Handle, id, MOD_CONTROL, VK_F1);
      RegisterHotKey(Handle, id1, MOD_CONTROL, VK_F2);
      RegisterHotKey(Handle, id2, MOD_CONTROL, VK_F3);
    end;
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      UnregisterHotKey(Handle,ID);
      UnregisterHotKey(Handle,ID1);
      UnregisterHotKey(Handle,ID2);
    end;
     procedure TForm1.WMHotKey(var Msg: TWMHotKey);
    begin
      if msg.HotKey=ID then
        button1.SetFocus
      else if Msg.HotKey=ID1 then
      edit1.SetFocus
      else if Msg.HotKey=ID2 then
        edit1.SetFocus;
        end;
      

  3.   

    在你的Form的OnShortCut中     if Msg.CharCode = vk_F5 then
            begin
            RadioGroup1.SetFocus ;
            Handled := True ;
            end ; //of if
      

  4.   

    楼主,你好象问过了这个问题呢?怎么,这样不行吗?
    1、将Form的Keypreview设置成True
    2、在Form的Onkeydown事件中编写如下代码:
       if key=vk_F5 then
           radiobutton1.setfocus;
      

  5.   

    RegisterHotKey函数原型及说明:
    BOOL RegisterHotKey(
      HWND hWnd,         // window to receive hot-key notification
      int id,            // identifier of hot key
      UINT fsModifiers,  // key-modifier flags
      UINT vk            // virtual-key code);
    参数 id为你自己定义的一个ID值,对一个线程来讲其值必需在0x0000 - 0xBFFF范围之内,对DLL来讲其值必需在0xC000 - 0xFFFF 范围之内,在同一进程内该值必须唯一
    参数 fsModifiers指明与热键联合使用按键,可取值为:MOD_ALT MOD_CONTROL MOD_WIN MOD_SHIFT
    参数 vk指明热键的虚拟键码 
    首先(举个例子):  
      RegisterHotKey(handle,globaladdatom('hot key'),MOD_ALT,vk_f12);
    然后在form中声明一个函数(过程):
      procedure hotkey(var msg:tmessage);message wm_hotkey;
    过程如下:
    procedure TForm1.hotkey(var msg:tmessage);
    begin
      if (msg.LParamHi=VK_F12) and (msg.LParamLo=MOD_ALT) then
      begin
       form1.show;
       SetForegroundWindow(handle);
      end;
    end;
    这样,不管你在什么地方,窗口就会显示出来。
    当然,你要GlobalDeleteAtom;unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
        aatom:atom;
        procedure hotkey(var msg:tmessage);message wm_hotkey;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    begin
      aatom:=globaladdatom('hot key');
      RegisterHotKey(handle,aatom,MOD_ALT,vk_f12);
    end;procedure TForm1.hotkey(var msg:tmessage);
    begin
      if (msg.LParamHi=VK_F12) and (msg.LParamLo=MOD_ALT) then
        SetForegroundWindow(handle);
    end;    procedure TForm1.FormDestroy(Sender: TObject);
    begin
     globalDeleteatom(aatom);
    end;end.
      

  6.   

    以前回答过类似问题。你看看是不是对你有帮助
    http://expert.csdn.net/Expert/topic/1376/1376141.xml?temp=.105221