-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Ctrl+C Enabler for PowerShell | ||
|
||
## Summary | ||
|
||
This is a .NET class library that allows you to enable Ctrl+C break on PowerShell console, always. | ||
|
||
## Why should be use this? | ||
|
||
In some case, a PowerShell console, which is launched from Visual Studio IDE external tools menu, doesn't accept Ctrl+C. | ||
|
||
This class library can fix it :) | ||
|
||
## How to install in your PowerShell? | ||
|
||
1. Download "CtrlCEnabler.dll" from [release page](releases), and save it into "%HOME%\Documents\WindowsPowerShell" folder. | ||
2. Open the PowerShell console and enter the following command: | ||
```powershell | ||
PS> notepad $PROFILE | ||
``` | ||
3. Then, the file "Microsoft.PowerShell_profile.ps1" is opened in a text editor. | ||
4. Append lines as follows at the bottom of "Microsoft.PowerShell_profile.ps1", and save it. | ||
```powershell | ||
# Enable Ctrl+C force. | ||
Add-Type -Path "$env:HOME\Documents\WindowsPowerShell\CtrlCEnabler.dll" | ||
[CtrlCEnabler]::EnableCtrlC() > $null | ||
``` | ||
|
||
After this instruction, the PowerShell console always enables Ctrl + C break, even when launched from Visual Studio's external tools menu. | ||
|
||
## How does it work? | ||
|
||
This class library just calls the `SetConsoleCtrlHandler` Win32 API. | ||
|
||
```csharp | ||
public static bool EnableCtrlC() | ||
{ | ||
return SetConsoleCtrlHandler(null, false); | ||
} | ||
``` | ||
|
||
See also: | ||
|
||
- https://docs.microsoft.com/en-us/windows/console/ctrl-c-and-ctrl-break-signals | ||
- https://docs.microsoft.com/en-us/windows/console/setconsolectrlhandler | ||
|
||
## LICENSE | ||
|
||
[The Unlicense](LICENSE) |