how to get find out the keyboard shortcut for the paste action?

Aleksei Ivanov alexey.ivanov at oracle.com
Tue Mar 5 15:40:34 UTC 2024


Hello Mark,

As far as I know, the shortcuts are localisable. For example, you use 
Ctrl+S to save a file in an English version, yet users of Spanish 
version of Windows use Ctrl+G (for Guardar) instead.

At the same time, the most common actions — Cut, Copy and Paste as well 
as Undo and Redo — usually have the same shortcuts across all languages 
and OS, although macOS uses Cmd instead of Ctrl. However, the shortcut 
for Redo is not as standard, Ctrl+Shift+Z and Ctrl+Y are used, both 
could be mapped at the same time.

I wonder what is the shortcut for Undo in German versions since German 
keyboard layout has Z and Y keys swapped. Does anyone know?

So, the shortcuts used in an application are controlled by the 
application and the shortcuts can be localised.

For this reason, the shortcuts are usually “hardcoded”.


@Jeremy
Does the input map of JTextArea contain shortcuts for Cut, Copy and Paste?

On 2024-03-04 20:42, mark.yagnatinsky at barclays.com wrote:
>
> Thanks!  I don’t have a particularly deep motivation here, other than 
> curiosity.
>
> If you’re wondering how my curiosity got piqued initially, it was 
> something like this:
>
> A while ago, someone at work was adding copy/paste support to some 
> component that didn’t have it.
>
> I noticed that they “hardcoded” the shortcut “ctrl C”.
>
> And I thought to myself:
>
> Swing already “knows” that this is the right keyboard shortcut, in the 
> sense that all components that support copy/paste “out of the box” use it.
>
> It would be nice if there was some way to ASK it to tell me what it 
> “knows”.
>
> *From:* Jeremy Wood <mickleness at gmail.com>
> *Sent:* Sunday, March 3, 2024 11:30 PM
> *To:* Yagnatinsky, Mark : Markets Pre Trade 
> <mark.yagnatinsky at barclays.com>; client-libs-dev at openjdk.org
> *Subject:* Re[2]: how to get find out the keyboard shortcut for the 
> paste action?
>
> CAUTION: This email originated from outside our organisation - 
> mickleness at gmail.com Do not click on links, open attachments, or 
> respond unless you recognize the sender and can validate the content 
> is safe.
>
> > But now I have a new question…
>
> > Is there any way to get the “usual” letter for a “common” operation?
>
> Hmm. Good question. Not that I know of.
>
> > Again, one could create a scratch text area and grovel through its 
> input map, but that seems hacky.
>
> I agree sifting through the L&F seems hacky.
>
> I don’t think I understand exactly what you’re trying to implement 
> here. If you give me a more concrete example: maybe I (or someone on 
> this list) can offer a more concrete suggestion?
>
> I’ll add some context in case this speaks to your question.
>
> By default Swing gets this information in places like 
> BasicTextUI#getInputMap(), which calls:
>
> InputMap shared=     (InputMap)DefaultLookup./get/(editor, this,     getPropertyPrefix() + ".focusInputMap”);
>
> The following works on my Mac & Windows machine (I think using JDK 
> 19), but I wouldn’t be surprised if it fails in other platforms / 
> L&F’s. It feels brittle, but it might (?) have potential:
>
> private KeyStroke getCopyKeyStroke() {
>
> InputMap inputMap = (InputMap) 
> UIManager.getDefaults().get("TextField.focusInputMap"); for (KeyStroke 
> keyStroke : inputMap.keys()) { Object action = 
> inputMap.get(keyStroke); if ("copy-to-clipboard".equals(action)) { 
> return keyStroke;         }     } /// this will show all the default 
> keystrokes //                
> System.out.println(Arrays.asList(inputMap.allKeys())); /return null; }
>
> Regards,
>
>  - Jeremy
>
> ------ Original Message ------
>
> From mark.yagnatinsky at barclays.com
>
> To mickleness at gmail.com; client-libs-dev at openjdk.org
>
> Date 3/3/24, 6:00:46 PM
>
> Subject RE: how to get find out the keyboard shortcut for the paste 
> action?
>
>     Thanks for the response!  I didn’t expect to get one at this point J
>
>     It does indeed answer my question!
>
>     (Though you didn’t quite get the name right: there’s no Ex at the end…
>
>     I take it you’ve done some Windows programming at some point)
>
>     But now I have a new question…
>
>     Is there any way to get the “usual” letter for a “common” operation?
>
>     For instance, lots of programs support copy and paste.
>
>     Is there a way to ask Java “what is the standard letter for paste”
>     and get back “V”?
>
>     Again, one could create a scratch text area and grovel through its
>     input map, but that seems hacky.
>
-- 
Regards,
Alexey


More information about the client-libs-dev mailing list