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 <micklen...@gmail.com>
Sent: Sunday, March 3, 2024 11:30 PM
To: Yagnatinsky, Mark : Markets Pre Trade <mark.yagnatin...@barclays.com>; 
client-libs-dev@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 - 
micklen...@gmail.com<mailto:micklen...@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.yagnatin...@barclays.com<mailto:mark.yagnatin...@barclays.com>
To micklen...@gmail.com<mailto:micklen...@gmail.com>; 
client-libs-dev@openjdk.org<mailto:client-libs-dev@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 ☺
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.

This message is for information purposes only. It is not a recommendation, 
advice, offer or solicitation to buy or sell a product or service, nor an 
official confirmation of any transaction. It is directed at persons who are 
professionals and is intended for the recipient(s) only. It is not directed at 
retail customers. This message is subject to the terms at: 
https://www.ib.barclays/disclosures/web-and-email-disclaimer.html<https://clicktime.symantec.com/15t5z4mRR1xMFCVmtWvPc?h=_ZThFXzMRdPMMViuNihJVxTtPiys_I6w5KRtMVx1Fb4=&u=https://www.ib.barclays/disclosures/web-and-email-disclaimer.html>.

For important disclosures, please see: 
https://www.ib.barclays/disclosures/sales-and-trading-disclaimer.html<https://clicktime.symantec.com/15t5uEa8xQGkqFfrLxXEz?h=aZV9E8QlHEZXtd0LrGSqdmqft6KqysFQSLGlZwqVa3M=&u=https://www.ib.barclays/disclosures/sales-and-trading-disclaimer.html>
 regarding marketing commentary from Barclays Sales and/or Trading desks, who 
are active market participants; 
https://www.ib.barclays/disclosures/barclays-global-markets-disclosures.html<https://clicktime.symantec.com/15t5ejzHaZDybRC5iHKo8?h=RfNE8pkWUQa8xg2DoVwTtgkk49rIoTtEUzNyxF83j9M=&u=https://www.ib.barclays/disclosures/barclays-global-markets-disclosures.html>
 regarding our standard terms for Barclays Investment Bank where we trade with 
you in principal-to-principal wholesale markets transactions; and in respect to 
Barclays Research, including disclosures relating to specific issuers, see: 
http://publicresearch.barclays.com<https://clicktime.symantec.com/15t5Zuo17wYPBUNAAiveW?h=-A3ytf21bzyvpw7G-HZH3xdk0z4TW9wQtXUIIHCyj8k=&u=http://publicresearch.barclays.com>.
__________________________________________________________________________________
If you are incorporated or operating in Australia, read these important 
disclosures: 
https://www.ib.barclays/disclosures/important-disclosures-asia-pacific.html<https://clicktime.symantec.com/15t5jaBa3Aua1N21Fqiwk?h=LNM_ZzBtmQ4icORcCbaHc_8simHhFf5h1R4P9VgQL4g=&u=https://www.ib.barclays/disclosures/important-disclosures-asia-pacific.html>.
__________________________________________________________________________________
For more details about how we use personal information, see our privacy notice: 
https://www.ib.barclays/disclosures/personal-information-use.html<https://clicktime.symantec.com/15t5pQNrVnbARJqvoQ86N?h=zaTRORm7ul9DlmzrjTzMBw2RNalvZJOfCr_u6f-IlR0=&u=https://www.ib.barclays/disclosures/personal-information-use.html>.
__________________________________________________________________________________

This message is for information purposes only. It is not a recommendation, 
advice, offer or solicitation to buy or sell a product or service, nor an 
official confirmation of any transaction. It is directed at persons who are 
professionals and is intended for the recipient(s) only. It is not directed at 
retail customers. This message is subject to the terms at: 
https://www.ib.barclays/disclosures/web-and-email-disclaimer.html. 

For important disclosures, please see: 
https://www.ib.barclays/disclosures/sales-and-trading-disclaimer.html regarding 
marketing commentary from Barclays Sales and/or Trading desks, who are active 
market participants; 
https://www.ib.barclays/disclosures/barclays-global-markets-disclosures.html 
regarding our standard terms for Barclays Investment Bank where we trade with 
you in principal-to-principal wholesale markets transactions; and in respect to 
Barclays Research, including disclosures relating to specific issuers, see: 
http://publicresearch.barclays.com.
__________________________________________________________________________________
 
If you are incorporated or operating in Australia, read these important 
disclosures: 
https://www.ib.barclays/disclosures/important-disclosures-asia-pacific.html.
__________________________________________________________________________________
For more details about how we use personal information, see our privacy notice: 
https://www.ib.barclays/disclosures/personal-information-use.html. 
__________________________________________________________________________________

Reply via email to