Thomas wrote:
1. We need to get access to the Scan Code that came along with a
pressed key's character (Asc) code. Sure, there is
Keyboard.AsyncKeyDown, but that's an _async_ function, meaning that at
the time we actually get to handle the KeyDown event, the user may
have already let go of that key again (can especially happen when
remote controlling a computer where keydown events gets pushed into
the system event queue without the keys actually ever being down on
that machine). I know that both Mac OS and Windows provide this
information, but it appears that RB just does not pass this up to us.

http://support.realsoftware.com/feedback/viewreport.php?reportid=cdwcumya

Vote early, vote often. You might want to add a note to the report (currently in Reviewed status -- will RB look at it again, or do we need to create a new report?) that the workaround (Keyboard.AsyncKeyDown) is not an option in some cases.

2. We need a function to convert a Scan code (including any possible
combinations of modifiers) into a character code (Asc code). I've once
written such a function for Mac OS, but we need something for Windows
and Linux as well.

If you're handling the event on keydown, then you've got the character code. You just need (1) to get the key code.

If you're handling the event at another time, then this step is necessary, but you can probably get away with a lookup table.

3. A reverse function of (2) may be good as well, although that may be
difficult. After all, there are several ways to enter a "+": both the
main block and the numeric block offer such a key, and when it comes
to compound keys (=E1, =FC, etc.) it's getting even more complicated.

Yeah, I don't think you can do this. There isn't a one to one mapping.

The goal is that I can write code where I can find out what chacter
code both a shiftted and a unshifted press of a specific key gives me
so that I can (a) tell if they're different and then (b) put those
chars codes into me menu as shortcuts by code. There are other uses,
but this is an example where it's useful (no, don't tell me that I can
build separate apps for separate languages instead - that's totally
besides the point and does not meet what's necessary)

When are you checking? On keydown events, or in a timer? There are different techniques depending on what you want to do.

If you check in the keydown event, you're immediately limiting yourself to those key combinations that actually get sent to keydown events. On Mac OS, that's pretty close to all combinations, but on Windows, alt- or control- combinations will never be sent.

If you check via timer polling, you are able to check all key combinations, but you need to be careful because even if you do something in response to a given combination, you're not actually removing that combination from the system queue. You can filter out keys that hit your keydown events, but you can't filter out keys that trigger other kinds of events (e.g. menu equivalents or alt-key mapped controls on Windows).

A third option is to create legitimate system shortcuts, either menu item shortcuts (what I gather you're trying to do) or actual hotkeys. Aaron's Windows Functionality Suite has sample code to do this on Windows and the Monkeybread plugin has code to do this on OS X. The advantage to making hotkeys is that hotkey events are proper system events and you don't have to worry about filtering out an event down the line.

So, has someone come up with solutions? Or is the AsyncKeyDown
actually giving the value from the event queue?

You can't trust AsyncKeyDown to be related to the current event. Not only is the timing shady, but it's possible the user has more than one key pressed at the time.

The cleanest option is probably to set up hotkeys or menu shortcuts, and use a separate dialog with timer-polling of AsyncKeyDown to let the user define the key combination for the hotkey. For this you'll just need a lookup table mapping key codes to character codes.

If you still want to access the keycode for an actual keydown event, you can do it via platform-specific plugins. For Carbon builds, you can use MonkeyBread's CarbonApplicationEventsMBS class. For Windows, you need a custom plugin that sets up a low level event hook using SetWindowsHookEx and caches the keycode for later retrieval. For Classic, you need a custom plugin that registers an event filter using REALRegisterEventFilter.

Eric Baumgartner
Inquirium
http://www.inquirium.net/
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to