Added new option "Require Alt key for accelerators"

With the option enabled keyboard accelerators will be triggered only if Alt key
is pressed as well.

This is how typical Windows keyboard accelerators work, to avoid
confusion with regular key presses.

Fixes #117
This commit is contained in:
ge0rdi
2022-12-19 14:30:59 +01:00
parent a7b6a80799
commit 23a1dc7e07
5 changed files with 17 additions and 6 deletions

View File

@@ -569,7 +569,7 @@ LRESULT CALLBACK CMenuContainer::SubclassSearchBox( HWND hWnd, UINT uMsg, WPARAM
{ {
pParent->SendMessage(WM_SYSKEYDOWN,wParam,lParam); pParent->SendMessage(WM_SYSKEYDOWN,wParam,lParam);
if (wParam==VK_MENU) if (wParam==VK_MENU)
pParent->ShowKeyboardCues(); pParent->ShowKeyboardCues(true);
} }
else else
{ {
@@ -5113,11 +5113,14 @@ void CMenuContainer::UpdateSearchResults( bool bForceShowAll )
} }
// Turn on the keyboard cues from now on. This is done when a keyboard action is detected // Turn on the keyboard cues from now on. This is done when a keyboard action is detected
void CMenuContainer::ShowKeyboardCues( void ) void CMenuContainer::ShowKeyboardCues( bool alt )
{ {
if (!GetSettingBool(L"EnableAccelerators")) if (!GetSettingBool(L"EnableAccelerators"))
return; return;
if (GetSettingBool(L"AltAccelerators") && !alt)
return;
if (!s_bKeyboardCues) if (!s_bKeyboardCues)
{ {
s_bKeyboardCues=true; s_bKeyboardCues=true;
@@ -5149,7 +5152,7 @@ LRESULT CMenuContainer::OnSysCommand( UINT uMsg, WPARAM wParam, LPARAM lParam, B
if ((wParam&0xFFF0)==SC_KEYMENU) if ((wParam&0xFFF0)==SC_KEYMENU)
{ {
// stops Alt from activating the window menu // stops Alt from activating the window menu
ShowKeyboardCues(); ShowKeyboardCues(true);
s_bOverrideFirstDown=false; s_bOverrideFirstDown=false;
} }
else else
@@ -5492,7 +5495,7 @@ bool CMenuContainer::CanSelectItem( int index, bool bKeyboard )
LRESULT CMenuContainer::OnKeyDown( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) LRESULT CMenuContainer::OnKeyDown( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
{ {
ShowKeyboardCues(); ShowKeyboardCues((HIWORD(lParam)&KF_ALTDOWN)!=0);
bool bOldOverride=s_bOverrideFirstDown; bool bOldOverride=s_bOverrideFirstDown;
s_bOverrideFirstDown=false; s_bOverrideFirstDown=false;
@@ -6115,6 +6118,9 @@ LRESULT CMenuContainer::OnChar( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& b
if (!GetSettingBool(L"EnableAccelerators")) if (!GetSettingBool(L"EnableAccelerators"))
return TRUE; return TRUE;
if (GetSettingBool(L"AltAccelerators") && !(HIWORD(lParam) & KF_ALTDOWN))
return TRUE;
if (wParam>=0xD800 && wParam<=0xDBFF) if (wParam>=0xD800 && wParam<=0xDBFF)
return TRUE; // don't support supplementary characters return TRUE; // don't support supplementary characters
@@ -8076,7 +8082,7 @@ HWND CMenuContainer::ToggleStartMenu( int taskbarId, bool bKeyboard, bool bAllPr
s_bNoDragDrop=!GetSettingBool(L"EnableDragDrop"); s_bNoDragDrop=!GetSettingBool(L"EnableDragDrop");
s_bNoContextMenu=!GetSettingBool(L"EnableContextMenu"); s_bNoContextMenu=!GetSettingBool(L"EnableContextMenu");
s_bKeyboardCues=bKeyboard&&GetSettingBool(L"EnableAccelerators"); s_bKeyboardCues=bKeyboard&&GetSettingBool(L"EnableAccelerators")&&!GetSettingBool(L"AltAccelerators");
s_RecentPrograms=(TRecentPrograms)GetSettingInt(L"RecentPrograms"); s_RecentPrograms=(TRecentPrograms)GetSettingInt(L"RecentPrograms");
if (s_RecentPrograms!=RECENT_PROGRAMS_NONE) if (s_RecentPrograms!=RECENT_PROGRAMS_NONE)
LoadMRUShortcuts(); LoadMRUShortcuts();

View File

@@ -808,7 +808,7 @@ private:
void ActivateItem( int index, TActivateType type, const POINT *pPt, ActivateData *pData=NULL ); void ActivateItem( int index, TActivateType type, const POINT *pPt, ActivateData *pData=NULL );
void ActivateTreeItem( const void *treeItem, RECT &itemRect, TActivateType type, const POINT *pPt, ActivateData *pData=NULL ); void ActivateTreeItem( const void *treeItem, RECT &itemRect, TActivateType type, const POINT *pPt, ActivateData *pData=NULL );
void DragTreeItem( const void *treeItem, bool bApps ); void DragTreeItem( const void *treeItem, bool bApps );
void ShowKeyboardCues( void ); void ShowKeyboardCues( bool alt );
void SetActiveWindow( void ); void SetActiveWindow( void );
void CreateBackground( int width1, int width2, int height1, int height2, int &totalWidth, int &totalHeight, bool bCreateRegion ); // width1/2, height1/2 - the first and second content area void CreateBackground( int width1, int width2, int height1, int height2, int &totalWidth, int &totalHeight, bool bCreateRegion ); // width1/2, height1/2 - the first and second content area
void BlendPatterns( unsigned int *bits, int width, int height ); void BlendPatterns( unsigned int *bits, int width, int height );

View File

@@ -4361,6 +4361,7 @@ CSetting g_Settings[]={
{L"BoldSettings",CSetting::TYPE_BOOL,IDS_BOLD_SETTINGS,IDS_BOLD_SETTINGS_TIP,1}, {L"BoldSettings",CSetting::TYPE_BOOL,IDS_BOLD_SETTINGS,IDS_BOLD_SETTINGS_TIP,1},
{L"ReportSkinErrors",CSetting::TYPE_BOOL,IDS_SKIN_ERRORS,IDS_SKIN_ERRORS_TIP,0}, {L"ReportSkinErrors",CSetting::TYPE_BOOL,IDS_SKIN_ERRORS,IDS_SKIN_ERRORS_TIP,0},
{L"EnableAccelerators",CSetting::TYPE_BOOL,IDS_ENABLE_ACCELERATORS,IDS_ENABLE_ACCELERATORS_TIP,1}, {L"EnableAccelerators",CSetting::TYPE_BOOL,IDS_ENABLE_ACCELERATORS,IDS_ENABLE_ACCELERATORS_TIP,1},
{L"AltAccelerators",CSetting::TYPE_BOOL,IDS_ALT_ACCELERATORS,IDS_ALT_ACCELERATORS_TIP,0,0,L"EnableAccelerators",L"EnableAccelerators"},
{L"SearchBoxSettings",CSetting::TYPE_GROUP,IDS_SEARCH_BOX}, {L"SearchBoxSettings",CSetting::TYPE_GROUP,IDS_SEARCH_BOX},
{L"SearchBox",CSetting::TYPE_INT,IDS_SHOW_SEARCH_BOX,IDS_SHOW_SEARCH_BOX_TIP,SEARCHBOX_TAB,CSetting::FLAG_BASIC}, {L"SearchBox",CSetting::TYPE_INT,IDS_SHOW_SEARCH_BOX,IDS_SHOW_SEARCH_BOX_TIP,SEARCHBOX_TAB,CSetting::FLAG_BASIC},

View File

@@ -639,6 +639,8 @@ BEGIN
IDS_PIC_COMMAND "User picture command" IDS_PIC_COMMAND "User picture command"
IDS_ENABLE_ACCELERATORS "Enable accelerators" IDS_ENABLE_ACCELERATORS "Enable accelerators"
IDS_ENABLE_ACCELERATORS_TIP "Use keyboard accelerators to execute menu commands" IDS_ENABLE_ACCELERATORS_TIP "Use keyboard accelerators to execute menu commands"
IDS_ALT_ACCELERATORS "Require Alt key for accelerators"
IDS_ALT_ACCELERATORS_TIP "Keyboard accelerators will be triggered only if Alt key is pressed"
END END
STRINGTABLE STRINGTABLE

View File

@@ -782,6 +782,8 @@
#define IDS_PINNED_PATH_TIP 3685 #define IDS_PINNED_PATH_TIP 3685
#define IDS_ENABLE_ACCELERATORS 3686 #define IDS_ENABLE_ACCELERATORS 3686
#define IDS_ENABLE_ACCELERATORS_TIP 3687 #define IDS_ENABLE_ACCELERATORS_TIP 3687
#define IDS_ALT_ACCELERATORS 3688
#define IDS_ALT_ACCELERATORS_TIP 3689
#define IDS_STRING7001 7001 #define IDS_STRING7001 7001
#define IDS_STRING7002 7002 #define IDS_STRING7002 7002
#define IDS_STRING7003 7003 #define IDS_STRING7003 7003