Fix for problems with "Keys and Sounds" (1 Viewer)

mswiege

MP Donator
  • Premium Supporter
  • October 15, 2008
    35
    12
    Home Country
    Germany Germany
    If you use the mapping of the keyboard keys to certain functions in the configuration.exe at "General/Keys and Sounds" you use the keydown event from the keyTextBox and simply cast the e.KeyValue from the event handler to a char to use that char as the new key. This is simply wrong! This works for some keys but not for all especially not for users with a non-English keyboard layout. The value passed by KeyValue represents a hardware-key of the keyboard not the ASCII representation of the char (but "randomly" these match for the most keys of the English keyboard layout but not for many keys of foreign layouts).
    The char of the key pressed is only passed by the KeyPress event. Because KeyPress is only fired for "normal" character keys and not for the F-Keys for example we can't just replace the keydown by keypress, instead we must extend it to use both events.
    So simply add a seconds event handler to keyTextBox (line 491 in GeneralKeys.cs)
    Code:
    this.keyTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.keyTextBox_KeyPress);
    and add the new function which is mainly a copy of the KeyDown handler but with the correct ToString() function.
    Code:
        private void keyTextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
          keyTextBox.Text = e.KeyChar.ToString().ToUpper();
    
          if (currentlySelectedNode != null)
          {
            if (currentlySelectedNode.Tag is KeyAction)
            {
              KeyAction action = currentlySelectedNode.Tag as KeyAction;
    
              action.Key = keyTextBox.Text;
    
              currentlySelectedNode.Nodes[1].Text = String.Format("Key = " + keyTextBox.Text);
            }
          }
        }

    The beauty is, that by adding this event handler instead of replacing keyDown, this still works with the special keys like "F1" because in that case only the old keyDown handles the key - the new KeyPress doesn't get called.
    And for the previous "wrong" keys, (e.g. the "+" sign gave with my German keyboard a "k") will now still store the "k" because keyDown still gets "falsely" called, but because KeyPress is called immediately after it the wrong value gets overwritten immediately.


    It think this (or another fix) should be added to the next release because it is definitely a bug if I press the "+" on my keyboard and a "k" is shown (BTW if I just save what configure.exe made in that case neither the "K" key nor the "+" work in MediaPortal).

    Hope I could help!

    Greetings
    Maik
     

    mswiege

    MP Donator
  • Premium Supporter
  • October 15, 2008
    35
    12
    Home Country
    Germany Germany
    Here is a patch file with the needed changes against the RC3 release.

    Any feedback of a developer would be much appreciated because I don't understand why this big bug is just ignored for such a long time especially if such a simple fix exists.
     

    Attachments

    • GeneralKeys.patch
      30.6 KB

    misterd

    Retired Team Member
  • Premium Supporter
  • April 4, 2006
    1,597
    314
    Home Country
    Germany Germany
    :D mswiege for spotting this issue and providing a patch for it.

    The patch is in SVN now and will be available with the next SVN build.

    MisterD
     

    Users who are viewing this thread

    Top Bottom