// Function to return the virtual key code of the win key state expected in the shortcut. Argument is used to decide which win key to return in case of both. If the current shortcut doesn't use both win keys then arg is ignored. Return NULL if it is not a part of the shortcut
// Since VK_WIN does not exist if right windows key is to be sent based on the argument, then return VK_RWIN as the win key (since that will be used to release it).
if(input==ModifierKey::Right)
{
returnVK_RWIN;
}
else
{
//return VK_LWIN by default
returnVK_LWIN;
}
}
}
// Function to return the virtual key code of the ctrl key state expected in the shortcut. Return NULL if it is not a part of the shortcut
DWORDShortcut::GetCtrlKey()const
{
if(ctrlKey==ModifierKey::Disabled)
{
returnNULL;
}
elseif(ctrlKey==ModifierKey::Left)
{
returnVK_LCONTROL;
}
elseif(ctrlKey==ModifierKey::Right)
{
returnVK_RCONTROL;
}
else
{
returnVK_CONTROL;
}
}
// Function to return the virtual key code of the alt key state expected in the shortcut. Return NULL if it is not a part of the shortcut
DWORDShortcut::GetAltKey()const
{
if(altKey==ModifierKey::Disabled)
{
returnNULL;
}
elseif(altKey==ModifierKey::Left)
{
returnVK_LMENU;
}
elseif(altKey==ModifierKey::Right)
{
returnVK_RMENU;
}
else
{
returnVK_MENU;
}
}
// Function to return the virtual key code of the shift key state expected in the shortcut. Return NULL if it is not a part of the shortcut
DWORDShortcut::GetShiftKey()const
{
if(shiftKey==ModifierKey::Disabled)
{
returnNULL;
}
elseif(shiftKey==ModifierKey::Left)
{
returnVK_LSHIFT;
}
elseif(shiftKey==ModifierKey::Right)
{
returnVK_RSHIFT;
}
else
{
returnVK_SHIFT;
}
}
// Function to check if the input key matches the win key expected in the shortcut
boolShortcut::CheckWinKey(constDWORD&input)const
{
if(winKey==ModifierKey::Disabled)
{
returnfalse;
}
elseif(winKey==ModifierKey::Left)
{
return(VK_LWIN==input);
}
elseif(winKey==ModifierKey::Right)
{
return(VK_RWIN==input);
}
// If ModifierKey::Both then return true if either left or right (VK_WIN does not exist)
else
{
return(VK_LWIN==input)||(VK_RWIN==input);
}
}
// Function to check if the input key matches the ctrl key expected in the shortcut
boolShortcut::CheckCtrlKey(constDWORD&input)const
{
if(ctrlKey==ModifierKey::Disabled)
{
returnfalse;
}
elseif(ctrlKey==ModifierKey::Left)
{
return(VK_LCONTROL==input);
}
elseif(ctrlKey==ModifierKey::Right)
{
return(VK_RCONTROL==input);
}
// If ModifierKey::Both then return true if either left or right or common
// Function to set a key in the shortcut based on the passed key code argument. Since there is no VK_WIN code, use the second argument for setting common win key. If isWinBoth is true then first arg is ignored. Returns false if it is already set to the same value. This can be used to avoid UI refreshing
// Since there isn't a key for a common Win key this is handled with a separate argument
if(isWinBoth)
{
if(winKey==ModifierKey::Both)
{
returnfalse;
}
winKey=ModifierKey::Both;
}
elseif(input==VK_LWIN)
{
if(winKey==ModifierKey::Left)
{
returnfalse;
}
winKey=ModifierKey::Left;
}
elseif(input==VK_RWIN)
{
if(winKey==ModifierKey::Right)
{
returnfalse;
}
winKey=ModifierKey::Right;
}
elseif(input==VK_LCONTROL)
{
if(ctrlKey==ModifierKey::Left)
{
returnfalse;
}
ctrlKey=ModifierKey::Left;
}
elseif(input==VK_RCONTROL)
{
if(ctrlKey==ModifierKey::Right)
{
returnfalse;
}
ctrlKey=ModifierKey::Right;
}
elseif(input==VK_CONTROL)
{
if(ctrlKey==ModifierKey::Both)
{
returnfalse;
}
ctrlKey=ModifierKey::Both;
}
elseif(input==VK_LMENU)
{
if(altKey==ModifierKey::Left)
{
returnfalse;
}
altKey=ModifierKey::Left;
}
elseif(input==VK_RMENU)
{
if(altKey==ModifierKey::Right)
{
returnfalse;
}
altKey=ModifierKey::Right;
}
elseif(input==VK_MENU)
{
if(altKey==ModifierKey::Both)
{
returnfalse;
}
altKey=ModifierKey::Both;
}
elseif(input==VK_LSHIFT)
{
if(shiftKey==ModifierKey::Left)
{
returnfalse;
}
shiftKey=ModifierKey::Left;
}
elseif(input==VK_RSHIFT)
{
if(shiftKey==ModifierKey::Right)
{
returnfalse;
}
shiftKey=ModifierKey::Right;
}
elseif(input==VK_SHIFT)
{
if(shiftKey==ModifierKey::Both)
{
returnfalse;
}
shiftKey=ModifierKey::Both;
}
else
{
if(actionKey==input)
{
returnfalse;
}
actionKey=input;
}
returntrue;
}
// Function to reset the state of a shortcut key based on the passed key code argument. Since there is no VK_WIN code, use the second argument for setting common win key.
// Function to return the name of the key with L or R prefix depending on the first argument. Second argument should be the name of the key without any prefix (ex: Win, Ctrl)