How to enable "Use Ctrl+Shift+C/V as Copy/Paste" for our command line app? #604

Closed
opened 2026-01-30 21:56:42 +00:00 by claunia · 5 comments
Owner

Originally created by @davidanthoff on GitHub (Mar 27, 2019).

How would we enable support for that out of the box for a command line app we ship? Would we somehow create a shortcut that has this configured as true during our setup? If so, I couldn't find any information how that would configured in the shortcut.

Or is there a way to enable this via say SetConsoleMode?

Originally created by @davidanthoff on GitHub (Mar 27, 2019). How would we enable support for that out of the box for a command line app we ship? Would we somehow create a shortcut that has this configured as true during our setup? If so, I couldn't find any information how that would configured in the shortcut. Or is there a way to enable this via say `SetConsoleMode`?
claunia added the Product-ConhostIssue-QuestionArea-SettingsResolution-Answered labels 2026-01-30 21:56:42 +00:00
Author
Owner

@miniksa commented on GitHub (Mar 27, 2019):

There is not a way to enable this from the outside by a running application. It's a user preference, not an application-settable feature.

There are technically ways to attempt to set it ahead of time with a registry key or by manipulating the shortcut contents as that's where this information is persisted.

The registry keys are set per user at HKCU\Console. I believe the specific key is InterceptCopyPaste; REG_DWORD; 0x1. If you set it in the root node, it will become the user's default for all console windows on the system. You'd have to set it in the subfolder that matches the path of your application.

As for the shortcut key, it's embedded in the LNK somewhere with an IPropertyStore from propsys.h and uses propvarutil.h to read/write data. The specific GUID for the InterceptCopyPaste node is currently not published for reasons I'm not clear of right now so I can't immediately disclose it. But an enterprising individual might be able to figure out which one is associated with this property.

How we choose registry or shortcut depends on how you launch. If it's launched without a shortcut, it uses the user defaults in HKCU\Console and then stacks the specific subfolder node for the executable on top of it. If it's launched with the shortcut, it does the same two first steps but then layers the shortcut contents on top at the end. You can find out more about this here: https://devblogs.microsoft.com/commandline/understanding-windows-console-host-settings/

So.... if you're enterprising and do a bit of digging and want to try to set this up ahead of time with an MSI or something with your software... power to you. You'd be doing it the same way we do. Caveat is that we're technically welcome to change the registry key persistence or shortcut embedding at any time as this is not a supported scenario, but you could decide to bank on us having better things to do for the foreseeable future.

If you want us to provide an API or something for it... I can mark this as a backlog deliverable and it'll get ranked accordingly.

@miniksa commented on GitHub (Mar 27, 2019): There is not a way to enable this from the outside by a running application. It's a user preference, not an application-settable feature. There are technically ways to attempt to set it ahead of time with a registry key or by manipulating the shortcut contents as that's where this information is persisted. The registry keys are set per user at `HKCU\Console`. I believe the specific key is `InterceptCopyPaste`; REG_DWORD; 0x1. If you set it in the root node, it will become the user's default for all console windows on the system. You'd have to set it in the subfolder that matches the path of your application. As for the shortcut key, it's embedded in the LNK somewhere with an `IPropertyStore` from `propsys.h` and uses `propvarutil.h` to read/write data. The specific GUID for the `InterceptCopyPaste` node is currently not published for reasons I'm not clear of right now so I can't immediately disclose it. But an enterprising individual might be able to figure out which one is associated with this property. How we choose registry or shortcut depends on how you launch. If it's launched without a shortcut, it uses the user defaults in `HKCU\Console` and then stacks the specific subfolder node for the executable on top of it. If it's launched with the shortcut, it does the same two first steps but then layers the shortcut contents on top at the end. You can find out more about this here: https://devblogs.microsoft.com/commandline/understanding-windows-console-host-settings/ So.... if you're enterprising and do a bit of digging and want to try to set this up ahead of time with an MSI or something with your software... power to you. You'd be doing it the same way we do. Caveat is that we're technically welcome to change the registry key persistence or shortcut embedding at any time as this is not a supported scenario, but you could decide to bank on us having better things to do for the foreseeable future. If you want us to provide an API or something for it... I can mark this as a backlog deliverable and it'll get ranked accordingly.
Author
Owner

@davidanthoff commented on GitHub (Mar 27, 2019):

Thanks!

I think as a first step publishing the GUID for the InterceptCopyPaste would be great.

I think probably the right thing to do would be that the julia setup (that is what I'm investigating here) writes both the registry key and the shortcut file with this change.

The one thing that would still not work, I believe, is if someone started julia from say a PowerShell prompt, right? In that case the setting for PowerShell for this would take over?

If this setting is not set, does the terminal then pass these keystrokes through to the command line app?

@davidanthoff commented on GitHub (Mar 27, 2019): Thanks! I think as a first step publishing the GUID for the `InterceptCopyPaste` would be great. I think probably the right thing to do would be that the julia setup (that is what I'm investigating here) writes both the registry key and the shortcut file with this change. The one thing that would still not work, I believe, is if someone started julia from say a PowerShell prompt, right? In that case the setting for PowerShell for this would take over? If this setting is not set, does the terminal then pass these keystrokes through to the command line app?
Author
Owner

@miniksa commented on GitHub (Mar 27, 2019):

I'm not certain whether the settings will stay inherited or switch to the other application's preferences. My gut says you're right and the Powershell settings would stay applied, but it's been a long time since I messed with this code (and don't honestly have time today to page that back into memory, sorry.)

If it's not set, then yes. The keystrokes go through to the application instead of being intercepted and acting on the host window level.

@miniksa commented on GitHub (Mar 27, 2019): I'm not certain whether the settings will stay inherited or switch to the other application's preferences. My gut says you're right and the Powershell settings would stay applied, but it's been a long time since I messed with this code (and don't honestly have time today to page that back into memory, sorry.) If it's not set, then yes. The keystrokes go through to the application instead of being intercepted and acting on the host window level.
Author
Owner

@miniksa commented on GitHub (May 18, 2019):

I think this is answered and the GUID should be in the sources now.

@miniksa commented on GitHub (May 18, 2019): I think this is answered and the GUID should be in the sources now.
Author
Owner

@eryksun commented on GitHub (May 18, 2019):

If it's launched without a shortcut, it uses the user defaults in HKCU\Console and then stacks the specific subfolder node for the executable on top of it.

The subkey name is based on the initial window title (STARTUPINFO.lpTitle) of the process that allocates the console. It happens that CreateProcess defaults to using the executable path as the window title if lpTitle is NULL. But note that it's not the resolved path, so the same executable accessed via different paths (e.g. junction, directory symlink, subst drive) corresponds to a different console subkey. If a specific title is set, the console uses the subkey for that title (with backslash replaced by underscore), and not the subkey for the executable path (e.g. if the title is set via CMD's start command, even with start "" "command", an empty title used to work around the simplistic argument parsing of the start command). When run by a shortcut, lpTitle is the .LNK file path, and this is flagged in the startup info as STARTF_TITLEISLINKNAME.

@eryksun commented on GitHub (May 18, 2019): > If it's launched without a shortcut, it uses the user defaults in HKCU\Console and then stacks the specific subfolder node for the executable on top of it. The subkey name is based on the initial window title (`STARTUPINFO.lpTitle`) of the process that allocates the console. It happens that `CreateProcess` defaults to using the executable path as the window title if `lpTitle` is `NULL`. But note that it's not the resolved path, so the same executable accessed via different paths (e.g. junction, directory symlink, subst drive) corresponds to a different console subkey. If a specific title is set, the console uses the subkey for that title (with backslash replaced by underscore), and *not* the subkey for the executable path (e.g. if the title is set via CMD's `start` command, even with `start "" "command"`, an empty title used to work around the simplistic argument parsing of the `start` command). When run by a shortcut, `lpTitle` is the .LNK file path, and this is flagged in the startup info as `STARTF_TITLEISLINKNAME`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#604