mirror of
https://github.com/microsoft/terminal.git
synced 2026-02-04 05:35:20 +00:00
Enable ctrl+shift to run terminal elevated from context menu (#15137)
This pull request adds the requirement for the shift key to be pressed in addition to the control key. References #14810 Implemented in #14873 This is follow up work from my last pull request that was merged that only required the control key to be pressed to launch the terminal as admin from the shell context menu. After some discussion it was decided that the shift key should be required as well as that is the norm on Windows. ## Validation Steps Performed Tested all combinations of shift+ctrl and verified that the terminal only requests elevation when a shift and control key are pressed together. The shell launches regularly if not.
This commit is contained in:
@@ -27,7 +27,7 @@ HRESULT OpenTerminalHere::Invoke(IShellItemArray* psiItemArray,
|
||||
IBindCtx* /*pBindContext*/)
|
||||
try
|
||||
{
|
||||
const auto runElevated = IsControlPressed();
|
||||
const auto runElevated = IsControlAndShiftPressed();
|
||||
|
||||
wil::com_ptr_nothrow<IShellItem> psi;
|
||||
RETURN_IF_FAILED(GetBestLocationFromSelectionOrSite(psiItemArray, psi.put()));
|
||||
@@ -204,14 +204,14 @@ HRESULT OpenTerminalHere::GetBestLocationFromSelectionOrSite(IShellItemArray* ps
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// This method checks if any of the ctrl keys are pressed during activation of the shell extension
|
||||
bool OpenTerminalHere::IsControlPressed()
|
||||
// Check is both ctrl and shift keys are pressed during activation of the shell extension
|
||||
bool OpenTerminalHere::IsControlAndShiftPressed()
|
||||
{
|
||||
const auto ControlPressed = 1U;
|
||||
short control = 0;
|
||||
short shift = 0;
|
||||
control = GetAsyncKeyState(VK_CONTROL);
|
||||
shift = GetAsyncKeyState(VK_SHIFT);
|
||||
|
||||
const auto control = GetKeyState(VK_CONTROL);
|
||||
const auto leftControl = GetKeyState(VK_LCONTROL);
|
||||
const auto rightControl = GetKeyState(VK_RCONTROL);
|
||||
|
||||
return WI_IsFlagSet(control, ControlPressed) || WI_IsFlagSet(leftControl, ControlPressed) || WI_IsFlagSet(rightControl, ControlPressed);
|
||||
// GetAsyncKeyState returns a value with the most significant bit set to 1 if the key is pressed. This is the sign bit.
|
||||
return control < 0 && shift < 0;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ struct
|
||||
private:
|
||||
HRESULT GetLocationFromSite(IShellItem** location) const noexcept;
|
||||
HRESULT GetBestLocationFromSelectionOrSite(IShellItemArray* psiArray, IShellItem** location) const noexcept;
|
||||
bool IsControlPressed();
|
||||
bool IsControlAndShiftPressed();
|
||||
|
||||
wil::com_ptr_nothrow<IUnknown> site_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user