开发者

Cocoa - keyboard reference numbers for hotkeys; any docs detailing these?

开发者 https://www.devze.com 2023-01-04 02:19 出处:网络
I\'m currently coding an app that has hotkey functionality, I\'ve done some reading and was surprised to see it is all done via an old Carbon API. However, perhaps the biggest dilemma is I am unable t

I'm currently coding an app that has hotkey functionality, I've done some reading and was surprised to see it is all done via an old Carbon API. However, perhaps the biggest dilemma is I am unable to calculate the "Keyboard Reference Number"s it requires.

The only app I h开发者_如何转开发ave seen that makes this possible (ASyncKey) won't work anymore as it was a Classic app.


I'd use the constants in Events.h whenever possible.

If you really want a reference document, there is a reference of the key codes for a US keyboard in Inside Macintosh: Text. While it was written for ADB keyboards, it's still accurate today.

You'll find the maps of the US keyboards in the web-page version hard to read; either consult the PDF (document page 1033, book page C-5), or use this handy crop from it.

Another solution is to use Key Codes, by Many Tricks, to display the key code for any key you press.


While the API to create hotkeys is a Carbon API, I wouldn't necessarily call it an "old" API; it's been updated to work for 64-bit apps and was the topic of one of the sessions at this year's WWDC (Session #145).

As for your question, I'm not quite sure what you mean. I got sick of trying to deal with (what I thought was) the class bloat of wrappers like PTHotKey, so I wrote my own. You can peruse the source on Github: http://github.com/davedelong/DDHotKey Hopefully that will help you figure out what's going on.

edit Key codes are how you indicate which key you want to tie your code to. These key codes are the "virtual" key codes, and they can be acquired in one of two ways:

  1. Perusing HIToolbox/Events.h and finding which key you want
  2. Extract it from -[NSEvent keyCode]

Even projects like ShortcutRecorder use one of these 2 approaches. I'm not aware of any others.

0

精彩评论

暂无评论...
验证码 换一张
取 消