Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

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

Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

pharo
Updates:
        Status: FixProposed

Comment #11 on issue 1064 by marianopeck: There are still problem with  
keyboard shortcuts in Windows
http://code.google.com/p/pharo/issues/detail?id=1064

from tn..


KeyboardEvent keyValue for 'ctrl + i' is evaluated to 9 as ASCII control
code,
and the value conflicts to Character tab value.
I tried to correct source code for this problem.
Below is the workaround for Pharo-1.1.1-OneClickCogVM on Windows XP.
--------------------
InputEventSensor>>processEvent:

processEvent: evt

...

  "Finally keyboard"
  type = EventTypeKeyboard
    ifTrue: [
      (evt at: 4)=0 ifTrue: [        "-- add --"
      "Sswap ctrl/alt keys if neeeded"
      KeyDecodeTable
        at: {evt at: 3. evt at: 5}
        ifPresent: [:a |
          evt
            at: 3 put: a first;
            at: 6 put: a first;  "-- add --"
            at: 5 put: a second].
      ].                                        "-- add --"
      "Update state for polling calls"
      modifiers := evt at: 5.
      ^evt].
...

In order to work this code, Preference Control and Alt keys must be set to
"Full matching".
Because ASCII control characters (e.g. ^i) is mapped to character code with
KeyDecodeTable, only at the time.

About key event, see InputEventFetcher class comment.
And it is interesting that to contrast implementations between Pharo and
Squeak4.2.
Each implementation is below.

Pharo: InputEventSensor>>processEvent:
Squeak4.2: EventSensor>>processEvent:

Thanks,


Reply | Threaded
Open this post in threaded view
|

Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

pharo

Comment #12 on issue 1064 by [hidden email]: There are still problem  
with keyboard shortcuts in Windows
http://code.google.com/p/pharo/issues/detail?id=1064

Hi, I'm tn.

'ctrl + m' problem is Cog VM bug.

Normally, when character key is pushed, keyboard events occur as follows on  
Squeak.

1. key press (down)
2. character (character code notification)
3. key release (up)

They are produced by a primitive method in IutEventFetcher >>  
primGetNextEvent.
But when ctrl + m is pushed, a character event doesn't occur.
Because 'ctrl + m' value is 13. The value is same as ENTER key.
Cog VM ignores WM_CHAR message(character event) when ENTER key is pushed.

The one of solution for this problem is to add CTRL key state to the  
if-condition.

-- sqWin32Window.c --

int recordKeyboardEvent(MSG *msg) {
   ...

   switch(msg->message) {
     ...

     case WM_CHAR:
     case WM_SYSCHAR:
       /* Note: VK_RETURN is recorded as virtual key ONLY */
       if(keyCode == 13  && !ctrl) return 1;            // add "&& !ctrl"
       pressCode = EventKeyChar;
       break;
     ...
   }
   ...

Note: ENTER keyCode is 13. But when ctrl + ENTER is pushed, the keyCode is  
10. So if the condition is revised, ctrl + m problem is corrected. but  
other behavior is not changed.


If you want to prevent to generate character event for CTRL + ENTER, you  
can add following code. By this way, we can produce not only ctrl+m  
(0x0D)'s character event but also ctrl+j (0x0A)'s one.

-- sqWin32Window.c --

// add this function
static int isNotKeyDownCtrlReturn(MSG* msgp){
     if(msgp->message == WM_KEYDOWN && msgp->wParam == VK_RETURN){
         if(GetKeyState(VK_CONTROL) & 0x8000) {
             return FALSE;
         }
     }
     return TRUE;
}

...

int ioProcessEvents(void)
{ static MSG msg;
   ...
       if(isNotKeyDownCtrlReturn(&msg)){  // add
         TranslateMessage(&msg);
       }                                  // add
       DispatchMessage(&msg);
   ...
}

...

int recordKeyboardEvent(MSG *msg) {
   ...

   if(pressCode == EventKeyDown && virtCode != 0 &&  
isNotKeyDownCtrlReturn(lastMessage) ) {
                                                    // add " &&  
isNotKeyDownCtrlReturn(lastMessage) "
     /* generate extra character event */
     ...
   }
   return 1;
}


Note: Below is a comment in the source code.

   /* note: several keys are not reported as character events;
      most noticably the mapped virtual keys. For those we
      generate extra character events here */

Those keys(e.g. arrow) should not be ascii code. ENTER key is not. but an  
extra character events is created for ENTER. I don't think this behavior is  
correct. As for ENTER key, an extra character event must not be generated  
and WM_CHAR should be processed. Please see msdn about TranslateMessage.

An attached file is source, which has been corrected by above way.
see also Comment 11.

Thanks,

Attachments:
        sqWin32Window.c  99 KB


Reply | Threaded
Open this post in threaded view
|

Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

pharo

Comment #13 on issue 1064 by [hidden email]: There are still problem  
with keyboard shortcuts in Windows
http://code.google.com/p/pharo/issues/detail?id=1064

<span style="color:red">test</span>


Reply | Threaded
Open this post in threaded view
|

Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

pharo

Comment #14 on issue 1064 by [hidden email]: There are still problem  
with keyboard shortcuts in Windows
http://code.google.com/p/pharo/issues/detail?id=1064

Hi, I'm tn.

'ctrl + m' problem is Cog VM bug.

Normally, when character key is pushed, keyboard events occur as follows on  
Squeak.

1. key press (down)
2. character (character code notification)
3. key release (up)

They are produced by a primitive method in IutEventFetcher >>  
primGetNextEvent.
But when ctrl + m is pushed, a character event doesn't occur.
Because 'ctrl + m' value is 13. The value is same as ENTER key.
Cog VM ignores WM_CHAR message(character event) when ENTER key is pushed.

The one of solution for this problem is to add CTRL key state to the  
if-condition.

-- sqWin32Window.c --

int recordKeyboardEvent(MSG *msg) {
   ...

   switch(msg->message) {
     ...

     case WM_CHAR:
     case WM_SYSCHAR:
       /* Note: VK_RETURN is recorded as virtual key ONLY */
       if(keyCode == 13  && !ctrl) return 1;            // add "&& !ctrl"
       pressCode = EventKeyChar;
       break;
     ...
   }
   ...

Note: ENTER keyCode is 13. But when ctrl + ENTER is pushed, the keyCode is  
10.
So if the condition is revised, ctrl + m problem is corrected.
but other behavior is not changed.


If you want to prevent to generate character event for CTRL + ENTER,
you can add following code. By this way, we can produce
not only ctrl+m (0x0D)'s character event but also ctrl+j (0x0A)'s one.

-- sqWin32Window.c --

// add this function
static int isNotKeyDownCtrlReturn(MSG* msgp){
     if(msgp->message == WM_KEYDOWN && msgp->wParam == VK_RETURN){
         if(GetKeyState(VK_CONTROL) & 0x8000) {
             return FALSE;
         }
     }
     return TRUE;
}

...

int ioProcessEvents(void)
{ static MSG msg;
   ...
       if(isNotKeyDownCtrlReturn(&msg)){  // add
         TranslateMessage(&msg);
       }                                  // add
       DispatchMessage(&msg);
   ...
}

...

int recordKeyboardEvent(MSG *msg) {
   ...

   if(pressCode == EventKeyDown && virtCode != 0 &&  
isNotKeyDownCtrlReturn(lastMessage) ) {
                                                    // add " &&  
isNotKeyDownCtrlReturn(lastMessage) "
     /* generate extra character event */
     ...
   }
   return 1;
}

An attached file is source, which has been corrected by above way.


Note: Below is a comment in the source code.

   /* note: several keys are not reported as character events;
      most noticably the mapped virtual keys. For those we
      generate extra character events here */

Those keys(e.g. arrow) should not be ascii code.
ENTER key is not. but an extra character events is created for ENTER.
I don't think this behavior is correct.
As for ENTER key, an extra character event must not be generated,
and WM_CHAR message should be processed.
Please see MSDN about TranslateMessage.

see also Comment 11.

Thanks,

Attachments:
        sqWin32Window.c  99 KB


Reply | Threaded
Open this post in threaded view
|

Fwd: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

Mariano Martinez Peck
Hi, I fordward this thread to the VM mailing list since it looks more appropiated.
David, here "tn" is proposing a fix. I am not qualified to take a look.
Hope it helps

Mariano

---------- Forwarded message ----------
From: <[hidden email]>
Date: Sat, Mar 5, 2011 at 9:23 PM
Subject: Re: [Pharo-project] Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows
To: [hidden email]



Comment #14 on issue 1064 by [hidden email]: There are still problem with keyboard shortcuts in Windows
Hi, I'm tn.

'ctrl + m' problem is Cog VM bug.

Normally, when character key is pushed, keyboard events occur as follows on Squeak.

1. key press (down)
2. character (character code notification)
3. key release (up)

They are produced by a primitive method in IutEventFetcher >> primGetNextEvent.
But when ctrl + m is pushed, a character event doesn't occur.
Because 'ctrl + m' value is 13. The value is same as ENTER key.
Cog VM ignores WM_CHAR message(character event) when ENTER key is pushed.

The one of solution for this problem is to add CTRL key state to the if-condition.

-- sqWin32Window.c --

int recordKeyboardEvent(MSG *msg) {
 ...

 switch(msg->message) {
   ...

   case WM_CHAR:
   case WM_SYSCHAR:
     /* Note: VK_RETURN is recorded as virtual key ONLY */
     if(keyCode == 13  && !ctrl) return 1;            // add "&& !ctrl"
     pressCode = EventKeyChar;
     break;
   ...
 }
 ...

Note: ENTER keyCode is 13. But when ctrl + ENTER is pushed, the keyCode is 10.
So if the condition is revised, ctrl + m problem is corrected.
but other behavior is not changed.


If you want to prevent to generate character event for CTRL + ENTER,
you can add following code. By this way, we can produce
not only ctrl+m (0x0D)'s character event but also ctrl+j (0x0A)'s one.

-- sqWin32Window.c --

// add this function
static int isNotKeyDownCtrlReturn(MSG* msgp){
   if(msgp->message == WM_KEYDOWN && msgp->wParam == VK_RETURN){
       if(GetKeyState(VK_CONTROL) & 0x8000) {
           return FALSE;
       }
   }
   return TRUE;
}

...

int ioProcessEvents(void)
{ static MSG msg;
 ...
     if(isNotKeyDownCtrlReturn(&msg)){  // add
       TranslateMessage(&msg);
     }                                  // add
     DispatchMessage(&msg);
 ...
}

...

int recordKeyboardEvent(MSG *msg) {
 ...

 if(pressCode == EventKeyDown && virtCode != 0 && isNotKeyDownCtrlReturn(lastMessage) ) {
                                                  // add " && isNotKeyDownCtrlReturn(lastMessage) "
   /* generate extra character event */
   ...
 }
 return 1;
}

An attached file is source, which has been corrected by above way.


Note: Below is a comment in the source code.

 /* note: several keys are not reported as character events;
    most noticably the mapped virtual keys. For those we
    generate extra character events here */

Those keys(e.g. arrow) should not be ascii code.
ENTER key is not. but an extra character events is created for ENTER.
I don't think this behavior is correct.
As for ENTER key, an extra character event must not be generated,
and WM_CHAR message should be processed.
Please see MSDN about TranslateMessage.


see also Comment 11.

Thanks,

Attachments:
       sqWin32Window.c  99 KB



Reply | Threaded
Open this post in threaded view
|

Re: [Vm-dev] Fwd: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

David T. Lewis
Thanks Mariano, I added this to http://bugs.squeak.org/view.php?id=7611
so the issue will be tracked.

The standard VM and the Cog VM share identical support code for this
function, so I am assuming that the issue affects all Windows VMs
(please correct me if this is wrong).

Andreas, Eliot - this would be a one-line fix in the support code
if you approve, and should be applied to both the trunk and the cog
branches.

Thanks,
Dave.


On Sun, Mar 06, 2011 at 04:12:24PM +0100, Mariano Martinez Peck wrote:

>  
> Hi, I fordward this thread to the VM mailing list since it looks more
> appropiated.
> David, here "tn" is proposing a fix. I am not qualified to take a look.
> Hope it helps
>
> Mariano
>
> ---------- Forwarded message ----------
> From: <[hidden email]>
> Date: Sat, Mar 5, 2011 at 9:23 PM
> Subject: Re: [Pharo-project] Issue 1064 in pharo: There are still problem
> with keyboard shortcuts in Windows
> To: [hidden email]
>
>
>
> Comment #14 on issue 1064 by [hidden email]: There are still problem
> with keyboard shortcuts in Windows
>
> http://code.google.com/p/pharo/issues/detail?id=1064
>
> Hi, I'm tn.
>
> 'ctrl + m' problem is Cog VM bug.
>
> Normally, when character key is pushed, keyboard events occur as follows on
> Squeak.
>
> 1. key press (down)
> 2. character (character code notification)
> 3. key release (up)
>
> They are produced by a primitive method in IutEventFetcher >>
> primGetNextEvent.
> But when ctrl + m is pushed, a character event doesn't occur.
> Because 'ctrl + m' value is 13. The value is same as ENTER key.
> Cog VM ignores WM_CHAR message(character event) when ENTER key is pushed.
>
> The one of solution for this problem is to add CTRL key state to the
> if-condition.
>
> -- sqWin32Window.c --
>
> int recordKeyboardEvent(MSG *msg) {
>  ...
>
>  switch(msg->message) {
>    ...
>
>    case WM_CHAR:
>    case WM_SYSCHAR:
>      /* Note: VK_RETURN is recorded as virtual key ONLY */
>      if(keyCode == 13  && !ctrl) return 1;            // add "&& !ctrl"
>      pressCode = EventKeyChar;
>      break;
>    ...
>  }
>  ...
>
> Note: ENTER keyCode is 13. But when ctrl + ENTER is pushed, the keyCode is
> 10.
> So if the condition is revised, ctrl + m problem is corrected.
> but other behavior is not changed.
>
>
> If you want to prevent to generate character event for CTRL + ENTER,
> you can add following code. By this way, we can produce
> not only ctrl+m (0x0D)'s character event but also ctrl+j (0x0A)'s one.
>
> -- sqWin32Window.c --
>
> // add this function
> static int isNotKeyDownCtrlReturn(MSG* msgp){
>    if(msgp->message == WM_KEYDOWN && msgp->wParam == VK_RETURN){
>        if(GetKeyState(VK_CONTROL) & 0x8000) {
>            return FALSE;
>        }
>    }
>    return TRUE;
> }
>
> ...
>
> int ioProcessEvents(void)
> { static MSG msg;
>  ...
>      if(isNotKeyDownCtrlReturn(&msg)){  // add
>        TranslateMessage(&msg);
>      }                                  // add
>      DispatchMessage(&msg);
>  ...
> }
>
> ...
>
> int recordKeyboardEvent(MSG *msg) {
>  ...
>
>  if(pressCode == EventKeyDown && virtCode != 0 &&
> isNotKeyDownCtrlReturn(lastMessage) ) {
>                                                   // add " &&
> isNotKeyDownCtrlReturn(lastMessage) "
>    /* generate extra character event */
>    ...
>  }
>  return 1;
> }
>
> An attached file is source, which has been corrected by above way.
>
>
> Note: Below is a comment in the source code.
>
>  /* note: several keys are not reported as character events;
>     most noticably the mapped virtual keys. For those we
>     generate extra character events here */
>
> Those keys(e.g. arrow) should not be ascii code.
> ENTER key is not. but an extra character events is created for ENTER.
> I don't think this behavior is correct.
> As for ENTER key, an extra character event must not be generated,
> and WM_CHAR message should be processed.
> Please see MSDN about TranslateMessage.
>
>
> see also Comment 11.
>
> Thanks,
>
> Attachments:
>        sqWin32Window.c  99 KB


Reply | Threaded
Open this post in threaded view
|

Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

pharo
In reply to this post by pharo

Comment #15 on issue 1064 by [hidden email]: There are still problem  
with keyboard shortcuts in Windows
http://code.google.com/p/pharo/issues/detail?id=1064

The workaround on Comment 11 is for only Windows.
I do not know well how the workaround works on other platforms.
Probably some shortcuts may not work.


Reply | Threaded
Open this post in threaded view
|

Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

pharo

Comment #16 on issue 1064 by [hidden email]: There are still problem  
with keyboard shortcuts in Windows
http://code.google.com/p/pharo/issues/detail?id=1064

'ctrl+.' doesn't also work. So I'm proposing a new solution.
The issue of shortcut key such as ctrl+i is solved by fixing VM, without  
repairing an image file of Pharo 1.1.1.
The workaround at Comment 11 is replaced to this solution.

(1)Problem
Thear are two problems.

First, key character event for Ctrl-key combination which can not encode to  
ASCII control character is not generated.
i.e. we can use only ASCII control character as Ctrl-key combo.
But some Ctrl-key combo which is not ASCII control character are used in  
Smalltalk.
In current Windows VM implementation, a key character event on Smalltalk is  
created based on WM_CHAR Windows messege.
Windos does not generate WM_CHAR message for Ctrl-key entry which can not  
encode to ASCII control character.

Second, when ctrl-key combo is pressed, ASCII control character is set to  
keyboard event imformation,
but the key's character code is not set.
Concretely, when '^A' is pressed, ASCII code '^A' is set to keyboard event,  
ASCII code 'A' is not set.
The second problem is probably on only Windows VM, is not on other  
platforms.

(2)Solution
Create key character events for Ctrl-key combinations when WM_KEYCHAR is  
fetched, not when WM_CHAR is fetched.
And then, by using ToAscii(or ToUnicode) Win32API function, convert virtual  
key code to ASCII code
  and set key's character to keyboard event object.
I think this approach is can be used to Squeak VM.

(3)Implementation
I corrected "sqWin32Window.c", please see also the attached file.

**** line 1060 in mapVirtualKey ****

     /* case VK_RETURN: return 13; */

**** line 1188 - 1236 new function ****

void recordCtrlKeyCharEvent(MSG* msg, sqKeyboardEvent* evt)
{
   BYTE keystate[256];
   WORD wd;
   WORD asciiKeyChar = 0;
   WORD asciiCtrlChar = 0xFFu;
   sqKeyboardEvent* extra;
   WPARAM virtualKeyCode = msg->wParam;

   assert(GetKeyState(VK_CONTROL) & 0x8000);

   /* Exit when only control key is pressed. */
   if(virtualKeyCode == VK_CONTROL) {
     return;
   }

   GetKeyboardState( keystate );

   /* get ASCII control character */
   switch(ToAscii( virtualKeyCode, HIWORD(msg->lParam), keystate, &wd, 0 )) {
   case 0:
     break;
   case 1:
     asciiCtrlChar = wd;
     break;
   default:
     return;
   }

   /* cancel ctrl key state */
   keystate[VK_CONTROL] = 0;

   /* get key character */
   if (ToAscii( virtualKeyCode, HIWORD(msg->lParam), keystate,  
&asciiKeyChar, 0 ) != 1) {
     return;
   }

   /* Exit when Ctrl + ENTER is pushed, because the combo is duplicate to ^N  
or ^M. */
   if (asciiKeyChar == 13) {
     return;
   }

   /* generate extra character event */
   extra = (sqKeyboardEvent*)sqNextEventPut();
   *extra = *evt;
   extra->pressCode = EventKeyChar;
   extra->charCode  = (asciiCtrlChar != 0xFFu ? asciiCtrlChar :  
asciiKeyChar) & 0xFF;
   extra->utf32Code = asciiKeyChar & 0xFF;
}

**** line 1276, 1304 - 1315 in recordKeyboardEvent ****

       /* if(keyCode == 13) return 1; */
...

   if(pressCode == EventKeyDown) {
     if (virtCode != 0) {
       /* generate extra character event */
       sqKeyboardEvent *extra = (sqKeyboardEvent*)sqNextEventPut();
       *extra = *evt;
       extra->pressCode = EventKeyChar;
     } else if (ctrl) {
       /* note: when virtCode is not zero, ctrl+key combination (e.g.  
ctrl+arrow)
          are not created by recordCtrlKeyCharEvent. */
       recordCtrlKeyCharEvent(lastMessage, evt);
     }
   }

**** line 1586 - 1595 new function ****
BOOL notCtrlDown(MSG* msg) {
   switch(msg->message) {
   case WM_KEYDOWN:
   case WM_SYSKEYDOWN:
     if (GetKeyState(VK_CONTROL) & 0x8000) {
       return FALSE;
     }
   }
   return TRUE;
}

**** line 1615- 1620 in ioProcessEvents ****
       /* Don't create WM_CHAR and WM_SYSCHAR message, when ctrl key is  
pressed. */
       if (notCtrlDown(&msg)) {
         TranslateMessage(&msg);
       }
       DispatchMessage(&msg);
     }


(4)Correct Pharo image file
To work some Ctrl+key combo whose key is non-alphabet, image file should be  
corrected.
e.g. below is a sample of correction for 'ctrl+.' on Pharo.

handleEvent: evt
     "Store the event in the queue if there's any"
     | type cmdBit ctrlBit | "# change #"
     type := evt at: 1.
     type = EventTypeKeyboard
         ifTrue: [
             cmdBit := 0. "# add #"
             ctrlBit := 0. "# add #"
             Preferences swapControlAndAltKeys
                     ifTrue: [ctrlBit := (evt at: 5) bitAnd: 2]
                     ifFalse:[cmdBit := (evt at: 5) bitAnd: 8]. "# add #"
             Preferences duplicateAllControlAndAltKeysSetting
                     ifTrue: [ctrlBit := (evt at: 5) bitAnd: 2]. "# add #"
             cmdBit := (cmdBit bitShift:8) bitOr:(ctrlBit bitShift: 10). "#  
add #"

             "Check if the event is a user interrupt"
             ((evt at: 4) = 0
                 and: [((evt at: 3)
                         bitOr: cmdBit) "# change #"
                             = interruptKey])
                     ifTrue: [
                         Display deferUpdates: false.
                         SoundService default shutDown.
                         self handleUserInterrupt].
             ^self ].

Thanks

tn

Attachments:
        sqWin32Window.c  100 KB


Reply | Threaded
Open this post in threaded view
|

Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

pharo

Comment #17 on issue 1064 by [hidden email]: There are still problem  
with keyboard shortcuts in Windows
http://code.google.com/p/pharo/issues/detail?id=1064

This attached file is a original "sqWin32Window.c" for comment 16.

Thanks

tn


Attachments:
        sqWin32Window.c.original  99.0 KB


Reply | Threaded
Open this post in threaded view
|

Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

pharo

Comment #18 on issue 1064 by [hidden email]: There are still problem  
with keyboard shortcuts in Windows
http://code.google.com/p/pharo/issues/detail?id=1064

> Create key character events for Ctrl-key combinations when WM_KEYCHAR is  
> fetched, ...

Sorry for my typo.
It is WM_KEYDOWN, not WM_KEYCHAR.

Thanks

tn


Reply | Threaded
Open this post in threaded view
|

Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

pharo

Comment #19 on issue 1064 by [hidden email]: There are still problem  
with keyboard shortcuts in Windows
http://code.google.com/p/pharo/issues/detail?id=1064

This issue should be moved to the COG tracker


Reply | Threaded
Open this post in threaded view
|

Re: Issue 1064 in pharo: There are still problem with keyboard shortcuts in Windows

pharo
Updates:
        Status: Closed

Comment #20 on issue 1064 by [hidden email]: There are still problem  
with keyboard shortcuts in Windows
http://code.google.com/p/pharo/issues/detail?id=1064

Moved to the Cog tacker: http://code.google.com/p/cog/issues/detail?id=26