THTkey with win-key support?

Anyway, to get the THotkey component in delphi to support Windows key?

Or does anyone know of a component that can do this?

Thanks heaps!

+3
delphi hotkeys
source share
5 answers

THotKey does not support Win-Key. I would add a checkbox next to it, possibly for the Win-Key modifier.

+1
source share

IMHO, it's good that THKKey does not support this.

Do not use the Windows key for keyboard shortcuts in your program, the "User Guide for Windows Vista Users" reads the following in Recommendations - Interaction - Keyboard :

Do not use the Windows logo modifier key for program shortcuts. The Windows logo key is reserved for use by Windows. Even if the Windows logo key combination is not used by Windows now, it may be in the future.

Even if the shortcut is not used by Windows, the use of such a keyboard shortcut will be confusing for users, since it will perform a function in your program, while other shortcuts, such as Win + E or Win + R, will activate the system - a common function that deactivates your program in progress.

Edit:

THotKey is a light wrapper around a system control that only supports what this system control supports. There is no documentary way to set anything other than the Alt, Ctrl, and Shift modifiers for the shortcut.

Perhaps you can create your own control to display shortcuts using the Windows key and set the global keyboard hook (look at the SetWindowsHookEx () API function).

+8
source share

I do not know if you can do this with the THotkey component.

But you can capture the left and right Windows key in any KeyDown event using:

if key = vk_LWin, then showmessage ('left'),
if key = vk_RWin, then showmessage ('right');

+3
source share

I am sure that this is possible - you need to make your own copy of {THotKey} and fine-tune it a bit to support the Win key as well. You need to add your own KeyDown () and Repaint () functions to this class.

Like this:

TMyCustomHotKey = class(TWinControl) public WinKey: boolean; procedure WMPaint(var Message: TWMPaint); message WM_PAINT; constructor Create(AOwner: TComponent); override; end; TMyHotKey = class(TMyCustomHotKey) 

..

  procedure TMyCustomHotKey.KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var a : integer; lbl : string; tmphot : tshortcut; begin a:= 0; if GetAsyncKeyState(VK_LWIN) <> 0 then a:= 1; if GetAsyncKeyState(VK_RWIN) <> 0 then a:= 1; if a=1 then begin winkey := true; end else begin winkey := false; end; rePaint(); } procedure TMyCustomHotKey.WMPaint(var Message: TWMPaint); var PS: TPaintStruct; DC: HDC; Canvas: TCanvas; i: Integer; X, Y: Integer; OldColor: TColor; Size: TSize; Max: Integer; s, Palabra, PrevWord: string; OldPen, DrawPen: HPEN; tmphot : tshortcut; Key: Word; Shift: TShiftState; lbl ,res: string; keyboardState: TKeyboardState; asciiResult: Integer; begin DC := Message.DC; if DC = 0 then DC := BeginPaint(Handle, PS); Canvas := TCanvas.Create; try OldColor := Font.Color; Canvas.Handle := DC; Canvas.Font.Name := Font.Name; Canvas.Font.Size := Font.Size; with Canvas do begin Brush.Color := Self.Color; FillRect(Self.ClientRect); Font.Color := OldColor; tmphot := gethotkey; ShortCutToKey(tmphot, Key, Shift); res := GetCharFromVKey(key); if (winkey = false) and (key = 0 ) and (tmphot = 0)then BEGIN lbl := 'Enter hotkey [CTRL/ALT/WIN] + Key' ; TextOut(1 ,1,lbl) ; END else begin if winkey then lbl := 'Win +' else lbl := ''; if ssAlt in Shift then lbl := lbl+ 'Alt + '; if ssShift in Shift then lbl := lbl+ 'Shift + '; if (not winkey) and (ssCtrl in Shift) then lbl := lbl+ 'Ctrl + '; lbl := lbl+ res; end; TextOut(1 ,1,lbl); end; finally if Message.DC = 0 then EndPaint(Handle, PS); end; Canvas.Free; SETCARETPOS(1,1); end; 
+3
source share
+2
source share

All Articles