Handling function keys in unix

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Handling function keys in unix

Guillermo Polito
 
So far, what I've learnt/found :).

1) I assume my build is using X11-display, since my keyboard events are generated there :P.

2) The X11 keyboard events are adapted to sq events in sqUnixX11.c >> x2sqKeyPlain

3) This build uses XLookupString, which brings char codes in Latin 1 instead of UTF-8.  But X11 seems to support UTF-8 :/.

4) When pressing a function key, XLookupString does not fill the buffer with chars...  and the KeySym is not handled.  I added a line like

    case XK_F1:     return  50;

and

Character class>>F1
    ^ self value: 50

to test, and It works :).  But I'm not sure which code is better to be returned yet :P.

5) My image now handles the F1, but only the keyDown and keyUp, since in sqUnixX11.c >> handleEvent I have something like:

if (ucs4) /* only generate a key char event if there's a code. */
        recordKeyboardEvent(keyCode, EventKeyChar, modifierState, ucs4);

6) I tried commenting the if, but that generates some garbage in my image when pressing Alt, Shift, Control...


So, some questions I have at this point:

- Which are the restrictions on the codes returned on translateCode (point 4) ? Are they ascii characters?  In the image I see the value is the keychar + the modifiers encoded
- Based on the prior question, Which codes should be assigned to function keys?
- I don't fully understand yet what a ucs4 code is, but the keysyms are translated to them in sqUnixX11.c >> xkeysym2ucs4 which looks pretty magical :).  Does someone know how this works?  The comments are not really helpful :(.


Thanks!
Guille, vming :)
Reply | Threaded
Open this post in threaded view
|

Re: Handling function keys in unix

Igor Stasenko

On 22 November 2011 15:51, Guillermo Polito <[hidden email]> wrote:

>
> So far, what I've learnt/found :).
>
> 1) I assume my build is using X11-display, since my keyboard events are generated there :P.
>
> 2) The X11 keyboard events are adapted to sq events in sqUnixX11.c >> x2sqKeyPlain
>
> 3) This build uses XLookupString, which brings char codes in Latin 1 instead of UTF-8.  But X11 seems to support UTF-8 :/.
>
> 4) When pressing a function key, XLookupString does not fill the buffer with chars...  and the KeySym is not handled.  I added a line like
>
>     case XK_F1:     return  50;
>
> and
>
> Character class>>F1
>     ^ self value: 50
>
> to test, and It works :).  But I'm not sure which code is better to be returned yet :P.
>
> 5) My image now handles the F1, but only the keyDown and keyUp, since in sqUnixX11.c >> handleEvent I have something like:
>
> if (ucs4) /* only generate a key char event if there's a code. */
>         recordKeyboardEvent(keyCode, EventKeyChar, modifierState, ucs4);
>
> 6) I tried commenting the if, but that generates some garbage in my image when pressing Alt, Shift, Control...
>
because these keys are not producing "characters", but they are kind
of "meta" keys which could modify the input.
as far as i understood, this line of code tells that it generates the
"KeyChar" event only if there's a character key pressed.
for other keys, like arrows, home/pgUp/pgDn etc you have key codes,
but not char codes, because there is no direct mapping between them
and any ascii/unicode character.

imagine that all keys on your keyboard having a number. Esc -  1 , F1 - 2 , etc.
So, these numbers are key codes. Now some keys can be directly
translated to characters when pressed (depending on keyboard
layout/language settings), but some of them not, and has only the key
code.

>
> So, some questions I have at this point:
>
> - Which are the restrictions on the codes returned on translateCode (point 4) ? Are they ascii characters?  In the image I see the value is the keychar + the modifiers encoded
> - Based on the prior question, Which codes should be assigned to function keys?
> - I don't fully understand yet what a ucs4 code is, but the keysyms are translated to them in sqUnixX11.c >> xkeysym2ucs4 which looks pretty magical :).  Does someone know how this works?  The comments are not really helpful :(.
>
>
cannot help with it, i am complete newbie concerning unix/X11 keyboard handling.

> Thanks!
> Guille, vming :)
>
>



--
Best regards,
Igor Stasenko.
Reply | Threaded
Open this post in threaded view
|

Re: Handling function keys in unix

Bert Freudenberg


On 22.11.2011, at 16:06, Igor Stasenko wrote:

>
> On 22 November 2011 15:51, Guillermo Polito <[hidden email]> wrote:
>>
>> So, some questions I have at this point:
>>
>> - Which are the restrictions on the codes returned on translateCode (point 4) ? Are they ascii characters?  In the image I see the value is the keychar + the modifiers encoded
>> - Based on the prior question, Which codes should be assigned to function keys?
>> - I don't fully understand yet what a ucs4 code is, but the keysyms are translated to them in sqUnixX11.c >> xkeysym2ucs4 which looks pretty magical :).  Does someone know how this works?  The comments are not really helpful :(.
>>
>>
> cannot help with it, i am complete newbie concerning unix/X11 keyboard handling.


ucs4 is UTF-32 (as google knows). It's plain unicode stored as an unsigned 32 bit value.

This is a character. So it is only meaningful in stroke events.

Function keys should only generate key down/up events, no strokes. And for encoding I suggest X11 codes (as defined in X11/keysymdef.h):

#define XK_F1 0xFFBE
#define XK_F2 0xFFBF
#define XK_F3 0xFFC0
#define XK_F4 0xFFC1
#define XK_F5 0xFFC2
#define XK_F6 0xFFC3
#define XK_F7 0xFFC4
#define XK_F8 0xFFC5
#define XK_F9 0xFFC6
#define XK_F10 0xFFC7
#define XK_F11 0xFFC8
#define XK_F12 0xFFC9

- Bert -

Reply | Threaded
Open this post in threaded view
|

Re: Handling function keys in unix

Guillermo Polito
In reply to this post by Igor Stasenko
 


On Tue, Nov 22, 2011 at 12:06 PM, Igor Stasenko <[hidden email]> wrote:

because these keys are not producing "characters", but they are kind
of "meta" keys which could modify the input.
as far as i understood, this line of code tells that it generates the
"KeyChar" event only if there's a character key pressed.
for other keys, like arrows, home/pgUp/pgDn etc you have key codes,
but not char codes, because there is no direct mapping between them
and any ascii/unicode character.

imagine that all keys on your keyboard having a number. Esc -  1 , F1 - 2 , etc.
So, these numbers are key codes. Now some keys can be directly
translated to characters when pressed (depending on keyboard
layout/language settings), but some of them not, and has only the key
code.

Hmm, but in my image, if I press the left arrow, I get a KeyPress :P.  So it's cheating! haha.

More, on, look at this for example:

  case XK_Left:    return 28;
    case XK_Up:        return 30;
    case XK_Right:    return 29;
    case XK_Down:    return 31;
    case XK_Insert:    return  5;
    case XK_Prior:    return 11;    /* page up */
    case XK_Next:    return 12;    /* page down */
    case XK_Home:    return  1;
    case XK_End:    return  4;

    case XK_KP_Left:    return 28;
    case XK_KP_Up:    return 30;
    case XK_KP_Right:    return 29;
    case XK_KP_Down:    return 31;
    case XK_KP_Insert:    return  5;
    case XK_KP_Prior:    return 11;    /* page up */
    case XK_KP_Next:    return 12;    /* page down */
    case XK_KP_Home:    return  1;
    case XK_KP_End:    return  4;

All those keys are treated as characters since their value is < 128 :S

What I'm wondering now is:  Should keybindings/shortcuts/"whatever name you want for them" be activated on keypress, keydown or keyup?

I'll have a look at eclipse source code xD.

Thank you very much :)
Guille

Reply | Threaded
Open this post in threaded view
|

Re: Handling function keys in unix

Guillermo Polito
 
Hmm,  here again :)

Eclipse help page talks about keystrokes, not keychars:

http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Faccessibility%2Fkeyboardshortcuts.htm

And so happens in my pharo image (but not in the VM :/).  So here we have an inconsistency (keyChar event on the vm, keyChar in the HandMorph, keystroke event on the rest of the image).

Don't you think it should be named keystroke everywhere?  Because If I stroke F4, it's a kestroke.  It will not have a charCode, but It'll have a keyValue.

Guille


On Tue, Nov 22, 2011 at 3:11 PM, Guillermo Polito <[hidden email]> wrote:


On Tue, Nov 22, 2011 at 12:06 PM, Igor Stasenko <[hidden email]> wrote:

because these keys are not producing "characters", but they are kind
of "meta" keys which could modify the input.
as far as i understood, this line of code tells that it generates the
"KeyChar" event only if there's a character key pressed.
for other keys, like arrows, home/pgUp/pgDn etc you have key codes,
but not char codes, because there is no direct mapping between them
and any ascii/unicode character.

imagine that all keys on your keyboard having a number. Esc -  1 , F1 - 2 , etc.
So, these numbers are key codes. Now some keys can be directly
translated to characters when pressed (depending on keyboard
layout/language settings), but some of them not, and has only the key
code.

Hmm, but in my image, if I press the left arrow, I get a KeyPress :P.  So it's cheating! haha.

More, on, look at this for example:

  case XK_Left:    return 28;
    case XK_Up:        return 30;
    case XK_Right:    return 29;
    case XK_Down:    return 31;
    case XK_Insert:    return  5;
    case XK_Prior:    return 11;    /* page up */
    case XK_Next:    return 12;    /* page down */
    case XK_Home:    return  1;
    case XK_End:    return  4;

    case XK_KP_Left:    return 28;
    case XK_KP_Up:    return 30;
    case XK_KP_Right:    return 29;
    case XK_KP_Down:    return 31;
    case XK_KP_Insert:    return  5;
    case XK_KP_Prior:    return 11;    /* page up */
    case XK_KP_Next:    return 12;    /* page down */
    case XK_KP_Home:    return  1;
    case XK_KP_End:    return  4;

All those keys are treated as characters since their value is < 128 :S

What I'm wondering now is:  Should keybindings/shortcuts/"whatever name you want for them" be activated on keypress, keydown or keyup?

I'll have a look at eclipse source code xD.

Thank you very much :)
Guille