Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Toggling input language...  (Read 5877 times)

0 Members and 1 Guest are viewing this topic.

Relic

  • Newbie
  • *
  • Posts: 43
    • View Profile
[SOLVED] Toggling input language...
« on: February 10, 2011, 08:57:10 am »
I've got a problem while toggling input language (Native/English) on the keyboard in my SFML application. In my OS Windows XP SP3 I set up the shortcut Shift+Ctrl for this option. But the language does not toggle. Other apps work fine. To do the trick I'm using the following key sequence: press Shift, press Ctrl, release Ctrl, press Alt, release Alt, release Shift.

Here is the test code:
Code: [Select]
#include "stdafx.h"
#include "SFML/Graphics.hpp"


int _tmain(int argc, _TCHAR* argv[])
{
  sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

sf::String str;
sf::Text text;

  while (window.IsOpened())
  {
    sf::Event evnt;
    while (window.GetEvent(evnt))
    {
      if (evnt.Type == sf::Event::Closed)
        window.Close();

      if (evnt.Type == sf::Event::TextEntered)
      {
str += evnt.Text.Unicode;
text.SetString(str);
      }
    }
 
    window.Clear();
    window.Draw(text);
    window.Display();
  }


return 0;
}

I guess there's something wrong with keyboard events handling. Is there any workaround for this behaviour? :?

Relic

  • Newbie
  • *
  • Posts: 43
    • View Profile
[SOLVED] Toggling input language...
« Reply #1 on: February 18, 2011, 07:27:34 am »
I'm still stuck with this issue. To delve deeper I traced windows messages that are being sent (posted) while I'm toggling input language. Using some tricks I managed to force my sfml window to react properly. This case is called 'Normal sequence'. But without tricks the issue still remains ('Abnormal sequence').
Quote
Normal sequence:

1. Press and release Ctrl+Shift to toggle input language to native. We can see windows messages, both WM_INPUTLANGCHANGEREQUEST and WM_INPUTLANGCHANGE.
Pay attention to the fact that toggling occurs after the key Ctrl is released and before the key Shift is released.
Charset successfully changed to 204, and the 'Q' key gives us the code 233.


P WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYUP nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:1 fUp:1
P WM_INPUTLANGCHANGEREQUEST fSysCharset:True hkl:04190419
S WM_IME_NOTIFY dwCommand:IMN_CLOSESTATUSWINDOW dwCommand:00000001 dwData:00000000
R WM_IME_NOTIFY
S WM_IME_NOTIFY dwCommand:IMN_OPENSTATUSWINDOW dwCommand:00000002 dwData:00000000
R WM_IME_NOTIFY
S WM_INPUTLANGCHANGE charset:204 hkl:04190419
R WM_INPUTLANGCHANGE
P WM_KEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:1 fUp:1

P WM_KEYDOWN nVirtKey:'Q' cRepeat:1 ScanCode:10 fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_CHAR chCharCode:'233' (233) cRepeat:1 ScanCode:10 fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYUP nVirtKey:'Q' cRepeat:1 ScanCode:10 fExtended:0 fAltDown:0 fRepeat:1 fUp:1

2. Again press and release Ctrl+Shift to toggle input language back to english. As above we can see both messages.
Charset successfully changed to 0, and the 'Q' key gives us the code 113.

 
P WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYUP nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:1 fUp:1
P WM_INPUTLANGCHANGEREQUEST fSysCharset:True hkl:04090409
S WM_IME_NOTIFY dwCommand:IMN_CLOSESTATUSWINDOW dwCommand:00000001 dwData:00000000
R WM_IME_NOTIFY
S WM_IME_NOTIFY dwCommand:IMN_OPENSTATUSWINDOW dwCommand:00000002 dwData:00000000
R WM_IME_NOTIFY
S WM_INPUTLANGCHANGE charset:0 hkl:04090409
R WM_INPUTLANGCHANGE
P WM_KEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:1 fUp:1

P WM_KEYDOWN nVirtKey:'Q' cRepeat:1 ScanCode:10 fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_CHAR chCharCode:'113' (113) cRepeat:1 ScanCode:10 fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYUP nVirtKey:'Q' cRepeat:1 ScanCode:10 fExtended:0 fAltDown:0 fRepeat:1 fUp:1

Abnormal sequence (no toggling):

P WM_KEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_INPUTLANGCHANGEREQUEST fSysCharset:True hkl:04190419
P WM_KEYUP nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:1 fUp:1
P WM_KEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:1 fUp:1

Or this (the real order of key pressing does not matter):

P WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_INPUTLANGCHANGEREQUEST fSysCharset:True hkl:04190419
P WM_KEYUP nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:1 fUp:1
P WM_KEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:1 fUp:1

Relic

  • Newbie
  • *
  • Posts: 43
    • View Profile
[SOLVED] Toggling input language...
« Reply #2 on: February 20, 2011, 02:56:14 pm »
Finally I managed to solve this issue. I had to make a small change in SFML source (WindowImplWin32.cpp). I changed the second parameter value from myHandle to NULL in WinAPI function PeekMessage. Now it peeks every message from the current thread's queue. I don't like to change 3d-party's libraries because of maintenance problems. But here it was the only way I had found.  :?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SOLVED] Toggling input language...
« Reply #3 on: February 20, 2011, 05:47:37 pm »
Interesting... do you know why doing this solves the problem?
Laurent Gomila - SFML developer

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
[SOLVED] Toggling input language...
« Reply #4 on: February 20, 2011, 07:01:08 pm »
Quote from: "Laurent"
Interesting... do you know why doing this solves the problem?


Doesn't SFML use a hidden window as a common OpenGL context for sharing? Maybe Windows sends these events to the first window opened by an application instead of the current window?

Relic

  • Newbie
  • *
  • Posts: 43
    • View Profile
[SOLVED] Toggling input language...
« Reply #5 on: February 21, 2011, 06:43:15 am »
A hidden topmost window this message is posted to, instead of main SFML render window would somehow explain this behaviour. But the windows utility Spy++ does not show that this is the case. I don't know what gives. :( To delve deeper and investigate the problem, I think I need to set up hooks for this message and its companions, but so far my solution works for me, and I'm gonna put the investigation on the back burner.
BTW, WM_INPUTLANGCHANGEREQUEST seems to be the most misterious message in Windows. Out of curiosity I made the same investigation on my laptop with Vista instead of XP, and found that this message was NEVER posted to an SFML window. But my application with patched WindowImplWin32.cpp works fine. :shock:
At the bottom part of MSDN page http://msdn.microsoft.com/en-us/library/ms632630%28v=vs.85%29.aspx with description of WM_INPUTLANGCHANGEREQUEST I found an interesting info (please find the paragraph 'Community Content' if you are interested). At least a few guys already had problems with this message before. :)

 

anything