macos 如何在 Mac 中使用 Command-c/Command-v 快捷方式来复制/粘贴文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7252749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Command-c/Command-v shortcut in Mac to copy/paste text?
提问by Brad
I have a Java Swing application that i want to run on Mac OS X. I want to use the normal Mac copy/paste shortcuts to copy/paste text to a text field in my Java application.
我有一个 Java Swing 应用程序,我想在 Mac OS X 上运行它。我想使用普通的 Mac 复制/粘贴快捷方式将文本复制/粘贴到我的 Java 应用程序中的文本字段。
Ctrl+c& Ctrl+vdoes the trick but i want to use Command+c& Command+vinstead. How can i do that?
Ctrl+ c& Ctrl+v可以解决问题,但我想改用Command+ c& Command+ v。我怎样才能做到这一点?
回答by cgull
If you're using a 3rd-party L&F implementation it probably doesn't support the Mac's native keyboard shortcuts. The following code should reinstate the Mac's keyboard shortcuts for JTextField
s after setting the L&F:
如果您使用的是 3rd-party L&F 实现,它可能不支持 Mac 的本机键盘快捷键。以下代码应JTextField
在设置 L&F 后恢复 Mac 的s键盘快捷键:
InputMap im = (InputMap) UIManager.get("TextField.focusInputMap");
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK), DefaultEditorKit.copyAction);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_DOWN_MASK), DefaultEditorKit.pasteAction);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.META_DOWN_MASK), DefaultEditorKit.cutAction);
Of course you'll only need to do this if you detect that the application is running on a Mac so that you don't affect the keyboard mappings for other OS's.
当然,您只需要在检测到应用程序在 Mac 上运行时才需要这样做,这样您就不会影响其他操作系统的键盘映射。
回答by Psyrus
Have you seen, know of or are using the SWT (Standard Widget Toolkit) maintained by Eclipse? That has a key press (SWT.COMMAND) for command.
您是否见过、知道或正在使用 Eclipse 维护的 SWT(Standard Widget Toolkit)?有一个按键(SWT.COMMAND)用于命令。
回答by user439407
Are you running pure Swing? If so it should do that automatically(note it may not make the little menu animation if you dont use an Application bundle). If not then you will have to consult the documentation for whatever API you are using.
你在运行纯 Swing 吗?如果是这样,它应该自动执行(请注意,如果您不使用应用程序包,它可能不会制作小菜单动画)。如果没有,那么您将不得不查阅您正在使用的任何 API 的文档。
Just tested it and it works fine on Snow Leopard.
刚刚测试它,它在雪豹上运行良好。