fHOTKEYSELECTOR
Quick Data
| Header file: | hotkeyselector.h |
| Object name: | fHOTKEYSELECTOR |
| Object index: | 1 of 1 Object |
General Description
The fHOTKEYSELECTOR is a very simple component, and should be familiar. If you show a properties dialog for say, a shortcut, there will be a box called 'Keyboard shortcut'. Pressing a combination of Shift, Alt, Control and another key will result in that value being placed into the box. This control is one of those controls, which can be quite useful for things like selecting hotkeys for your program to use.
The only other note which needs to be made is about how the control works. The user needs to give the control keyboard focus and then press the keys that they want. However, if the hotkey is already taken by another application or is assigned to a shortcut, then pressing this key combination will run that program or alert that application.
This component is derived from _GUIBASE, and inherits the properties from that.
Primary Options
|
| Name |
Description |
Value |
|
| There are no Primary properties for this component. Just use 0. |
Secondary Options
|
| Name |
Description |
Value |
|
| There are no Secondary properties for this component. Just use 0. |
Key modifiers
|
| Name |
Description |
Value |
|
|
keyALT
|
This constant is used for the ALT key, whether encoding or decoding.
|
HOTKEYF_ALT
|
|
keySHIFT
|
This constant is used for the SHIFT key, whether encoding or decoding.
|
HOTKEYF_SHIFT
|
|
keyCONTROL
|
This constant is used for the CONTROL key, whether encoding or decoding.
|
HOTKEYF_CONTROL
|
|
keyEXTENDED
|
This constant is used for an extended key, for example the Windows key. Used whether encoding or decoding.
|
HOTKEYF_EXT
|
Methods
|
| Prototype |
Description |
|
|
void SetHotkey(int SpecialKeys, int LetterKey);
|
This function presets what the hotkey is. SpecialKeys is a combination of the values from the above table, and LetterKey is an ordinary letter key.
|
|
int GetSpecialKeys(void);
|
This function returns the special keys that are in the box. The value returned is one or more of the values from the table above. Special keys will be the combination of CTRL, ALT, or SHIFT that was selected.
|
|
int GetLetterKey(void);
|
This function returns the letter key of the keys that are in the box. The value returned is an ASCII value.
|
|
void MakeInvalid(int SpecialKeys, int LetterKey, int AlternateSpecialKeys, int AlternateLetterKey);
|
This function sets a combination of keys that are not allowed in the box. If the combination which is not allowed is pressed, then it will be replaced with the alternate key combination specified. Please note that when calling this function, you can use the following values in addition to the ones listed in the table above for the SpecialKeys: (taken from the Win32 SDK Reference)
- HKCOMB_A - ALT
- HKCOMB_C - CTRL
- HKCOMB_CA - CTRL+ALT
- HKCOMB_NONE - Unmodified keys
- HKCOMB_S - SHIFT
- HKCOMB_SA - SHIFT+ALT
- HKCOMB_SC - SHIFT+CTRL
- HKCOMB_SCA - SHIFT+CTRL+ALT
Please do not use the values listed here for anything other than this function.
|
Events
Please note that the events listed here are done in pairs; one as a property, and the other as a function. The property is assigned a function name, ie. Object.OnClick = &FunctionName, whilst the function is called to verify that an event has occured. Please see the chapter on event handling for information on how to use these correctly.
|
| Prototype |
Description |
Sent under |
|
bool CheckChanged(wParam, lParam);
void (*OnChange)(fHOTKEYSELECTOR* Sender);
|
This event occurs when the user has changed the hotkey that is in the box.
|
WM_COMMAND
|
Sample Code
The following snippet gives a basic idea of how to use this component.
//Create one of these controls...
fHOTKEYSELECTOR HKSel;
HKSel.CreateWin(&Window, "", ID_HKS, 0, 0);
//Apply a restriction.
//In this case, ban ALT+SHIFT+Q, and replace it with ALT+CTRL+K
HKSel.MakeInvalid(keyALT | keySHIFT, 'Q', keyALT | keyCONTROL, 'K');
//Get the value.
int Result = HKSel.GetSpecialKeys();
//Determine what keys pressed.
if (Result & keyALT) //ALT was in the combination.
if (Result & keyCONTROL) //CONTROL was in the combination.
if (Result & keySHIFT) //SHIFT was in the combination.
if (Result & keyEXTENDED) //Another key was in the combination (ie. Windows key)
//And finally, get the key that was pressed.
int KeyPressed = HKSel.GetLetterKey();
if (KeyPressed == 'Q') //Q was pressed. See how it works?