tags:

views:

77

answers:

1

A very simple test case:

alt text

procedure TForm3.btnCopyClick(Sender: TObject);
begin
  HotKey2.HotKey := HotKey1.HotKey;
end;

Press "PgDn" key in the first THotKey and "Page Down" is displayed. Click the ==> button and the second THotKey will display "Num 3".

Similar things happen if modifiers (Shift etc) are pressed. The behaviour also applies to PgUp, Home, End and Ins.

As far as I can see, this happens somewhere inside Windows :( Correct virtual code (34) is sent along the HKM_SETHOTKEY message.

Does somebody know of a nice workaround? Currently, the only idea I got is to send fake WM_KEYDOWN/WM_KEYUP messages with parameters set to VK_NEXT and MapVirtualKey(VK_NEXT) but that is kinda ugly ...


Hotkeys are just simple THotKeys:

  object HotKey1: THotKey
    Left = 12
    Top = 14
    Width = 121
    Height = 19
    InvalidKeys = []
    Modifiers = []
    TabOrder = 0
  end
  object HotKey2: THotKey
    Left = 194
    Top = 14
    Width = 121
    Height = 19
    InvalidKeys = []
    Modifiers = []
    TabOrder = 1
  end
  object btnCopy: TButton
    Left = 143
    Top = 14
    Width = 42
    Height = 19
    Caption = '==>'
    TabOrder = 2
    OnClick = btnCopyClick
  end
+10  A: 

The hkExt modifier is important and needs to be copied, too:

HotKey2.HotKey := HotKey1.HotKey;
HotKey2.Modifiers := HotKey1.Modifiers;
TOndrej
Thanks!Actually, it is only hkExt that must be copied separately, all other Modifiers are packed into the HotKey. (In real world, I had problems persisting THotKey state, but that way it was easier to show the problem.)
gabr