1 Reply Latest reply: Nov 8, 2014 12:27 AM by aparpara RSS

    Keyboard layout switching hangs Flash Player plugin

    aparpara Community Member

      Hello!

       

      I'm using a software component switching the keyboard layout programmatically. It works OK except with Flash Player plugins in Firefox and Chrome. When the plugin is active, trying to switch the keyboard layout results in that browser comletely freezes. I've written a small C program to test the issue (see the message bottom), and the program freezes at the line

      SendMessageA(hwnd, WM_INPUTLANGCHANGEREQUEST, 0, (LPARAM)layout);

       

      I've tryed switching off the Flash Player hardware acceleration and even starting Windows in safe mode with network drivers — nothing helps. But Opera and IE work ok and layout switching from the system task panel also works ok. Who can tell what may be the cause?

       

      My system is:

      Lenovo G770

      Windows 7 Home Basic 64 SP1

      Flash Player 15.0.0.189

       

      #include <windows.h>

      #include <stdio.h>

       

      #define MAX_LAYOUT_NUMBER 32

       

      int main(int argc, char **argv)

      {

        HKL layouts[MAX_LAYOUT_NUMBER];

        int nLayouts;

        HWND hwnd = 0;

        DWORD threadID, processID;

        HKL layout;

        int i;

        BOOL found;

       

        nLayouts = GetKeyboardLayoutList(MAX_LAYOUT_NUMBER, layouts);

        if (nLayouts <= 0) {

          fprintf(stderr, "Error: GetKeyboardLayoutList returned %d\n", nLayouts);

          return 1;

        }

        if (nLayouts == 1) {

          printf("Only one keyboard layout detected\n");

          return 0;

        }

       

        if (argc > 1) {

          if (sscanf(argv[1], "%X", &hwnd) != 1) {

            fprintf(stderr, "Error: Invalid window handle \"%s\"\n", argv[1]);

            return 1;

          }

        }

       

        // Delay for user to switch to the desired application

        Sleep(5000);

       

        if (hwnd == 0) {

          hwnd = GetForegroundWindow();

          if (hwnd == NULL) {

            fprintf(stderr, "Error: GetForegroundWindow returned NULL\n");

            return 1;

          }

        }

        {

          char buf[MAX_PATH];

          if (GetWindowTextA(hwnd, buf, MAX_PATH) > 0)

            printf("The target window is %.8X (%s)\n", hwnd, buf);

          else

            printf("The target window is %.8X\n", hwnd);

        }

       

        threadID = GetWindowThreadProcessId(hwnd, &processID);

        if (threadID == 0) {

          fprintf(stderr, "Error: GetWindowThreadProcessId returned NULL\n");

          return 1;

        }

        printf("Its process and thread IDs are %.8X and %.8X\n", processID, threadID);

       

        layout = GetKeyboardLayout(threadID);

        if (layout == NULL) {

          fprintf(stderr, "Error: GetKeyboardLayout returned NULL\n");

          return 1;

        }

        printf("The current keyboard layout is %.8X\n", layout);

       

        found = FALSE;

        for (i = 0; i < nLayouts; ++i)

          if (layout == layouts[i]) {

          found = TRUE;

            layout = layouts[i < nLayouts-1 ? i + 1 : 0];

            break;

          }

        if (!found) {

          fprintf(stderr, "Error: Can't find the current layout in the list\n");

          return 1;

        }

       

        printf("Switching to %.8X\n", layout);

        SendMessageA(hwnd, WM_INPUTLANGCHANGEREQUEST, 0, (LPARAM)layout);

       

        layout = GetKeyboardLayout(threadID);

        if (layout == NULL) {

          fprintf(stderr, "Error: GetKeyboardLayout returned NULL\n");

          return 1;

        }

        printf("The new keyboard layout is %.8X\n", layout);

       

        return 0;

      }