Professional Web Applications Themes

From character to keycode - Mac Programming

How can you translate from a character to a keycode? I imagine it depends on language, keyboard, etc. Thanks!...

  1. #1

    Default From character to keycode

    How can you translate from a character to a keycode? I imagine it
    depends on language, keyboard, etc.

    Thanks!
    macxguy Guest

  2. #2

    Default Re: From character to keycode

    In article <google.com>, macxguy
    <com> wrote:
     

    There is this sample
    <http://developer.apple.com/samplecode/Sample_Code/Archive/Human_Interfa
    ce_Toolbox/iGetKeys.htm> but it is deprecated for unspecified reasons.
    James Guest

  3. #3

    Default Re: From character to keycode

    In article <031020030920483783%com.invalid>,
    "James W. Walker" <com.invalid> wrote:
     
    >
    > There is this sample
    > <http://developer.apple.com/samplecode/Sample_Code/Archive/Human_Interfa
    > ce_Toolbox/iGetKeys.htm> but it is deprecated for unspecified reasons.[/ref]

    I believe it's deprecated because this is impossible in the general
    case. It's possible to generate characters that don't have a single
    corresponding keystroke. If you're doing this translation because you
    want to figure out how the user typed the characters that you just got,
    do so with the understanding that your results will be wrong for some
    users and that you might not get any results for others.

    -Eric

    --
    Eric Albert edu
    http://rescomp.stanford.edu/~ejalbert/
    Eric Guest

  4. #4

    Default Re: From character to keycode

    In article <stanford.edu>, Eric
    Albert <edu> wrote:
     
    >
    > I believe it's deprecated because this is impossible in the general
    > case.[/ref]

    It may also have to do with a bug that I filed against the sample code
    a year or so ago. I pointed out that the sample does not work with
    KCHRs installed in the Keyboard Layouts folder, as doented in
    <http://developer.apple.com/technotes/tn2002/tn2056.html>, due to the
    way that the iGetKeys sample gets the current keyboard layout. I
    pointed out that the sample could be fixed using new calls in
    Keyboards.h, but I guess they found it easier to deprecate the sample
    than to fix it.
    James Guest

  5. #5

    Default Re: From character to keycode

    I should note that the reason I want to do this is to use
    RegisterHotKeyEvent.

    However, there seems to be no easy way to get the keycode. I just
    want to take a standard character and figure out its keyCode. (I am
    using a fairly complex framework, and there's no way to get the
    keyCode from the event without re-writing a whole chunk of it).

    Thanks!

    "James W. Walker" <com.invalid> wrote in message news:<041020030017257494%com.invalid>... 
    > >
    > > I believe it's deprecated because this is impossible in the general
    > > case.[/ref]
    >
    > It may also have to do with a bug that I filed against the sample code
    > a year or so ago. I pointed out that the sample does not work with
    > KCHRs installed in the Keyboard Layouts folder, as doented in
    > <http://developer.apple.com/technotes/tn2002/tn2056.html>, due to the
    > way that the iGetKeys sample gets the current keyboard layout. I
    > pointed out that the sample could be fixed using new calls in
    > Keyboards.h, but I guess they found it easier to deprecate the sample
    > than to fix it.[/ref]
    macxguy Guest

  6. #6

    Default Re: From character to keycode

    > I should note that the reason I want to do this is to use 

    I am doing the same in one of my (not released yet) applications. I
    implemented a very simple way for getting keycodes for simple low letter
    characters: I just create a table for all keys and its resulting characters.
    So I can search in this table for the keycode of a character. Note that it
    really only works for simple low letter characters that can be put in on the
    keyboard with just one keypress (and no additional modifier keys pressed).
    This is e.g. useful for getting keycodes for the low letter "z" or "y" that
    are often at different locations depending on the keyboard language layout.
    (Also note that this function is not thread-safe because of the static
    variables.)

    static UInt32 findKeyCodeForCharacter(char c) {
    static bool done = NO;
    static char key2character[128];
    int i;
    if (!done) {
    UInt32 state;
    const void *transData = (const void
    *)GetScriptManagerVariable(smKCHRCache);
    for(i = 0; i < 128; i++) {
    state = 0;
    key2character[i] = (char)KeyTranslate(transData, (UInt16)i,
    &state);
    }
    done = YES;
    }
    for(i = 0; i < 128; i++) {
    if (key2character[i] == c) {
    return (UInt32)i;
    }
    }
    return (UInt32)-1;
    }

    Hope this helps,
    Mani
    --
    LittleSecrets, iVolume, SharingMenu:
    http://www.mani.de/

    Manfred Guest

  7. #7

    Default Re: From character to keycode

    dans l'article google.com, macxguy à
    com a écrit le 4/10/03 23:07:
     

    I think you should be able to call ConvertEventRefToEventRecord. However I
    do not know if the keycode is properly filled by this function.

    Eric

    Eric Guest

  8. #8

    Default Re: From character to keycode

    post a keyboard event with
    CGPostKeyboardEvent( 0, index, true );
    CGPostKeyboardEvent( 0, index, false );
    for index 0 to 128 with a periodic task of 0.1 second
    and overide keyDown to catch the keycode in the window

    In article <google.com>,
    com (macxguy) wrote:
     
    Alain Guest

Similar Threads

  1. Extract Character By Character in PDF
    By s.r.krish@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 14
    Last Post: March 14th, 12:14 PM
  2. Determining the Browser and event.keyCode vs. event.which
    By Nathan Sokalski in forum ASP.NET Building Controls
    Replies: 4
    Last Post: March 11th, 06:36 AM
  3. InDesign ME Character Problem! Character-Change by Printing or saving *.PS!
    By gree@adobeforums.com in forum Adobe Indesign Windows
    Replies: 48
    Last Post: May 25th, 02:07 PM
  4. The keycode for the "print screen" button
    By Welshy31 in forum Macromedia Director Lingo
    Replies: 2
    Last Post: November 28th, 04:17 PM
  5. film loop rotation, keycode problems..
    By deepcover webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 3
    Last Post: October 11th, 08:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139