Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Setting KeyLabels best practice (Read 2218 times)
ErikJ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 26th, 2019
Setting KeyLabels best practice
Mar 29th, 2019 at 3:36pm
Print Post  
Can you point me to example of using the SetKeyLabels property?

Should that be called once upon initializing or every time the culture changes?  If default language is inherently configured in layout, is the SetKeyLabels necessary to "reset" the vk back after changing cultures? For example if default is English and culture is then changed to Spanish and then back to English what would be the necessary sequencing?

Ideally I'd like to use this feature dynamically rather than having different layouts for each supported culture in order to utilize already existing translation methods for defined phrases.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2160
Joined: Oct 19th, 2005
Re: Setting KeyLabels best practice
Reply #1 - Apr 1st, 2019 at 9:37am
Print Post  
We've added that recently for a customer and haven't collected much of best practices so far Smiley You can find their use case here -
https://mindfusion.eu/Forum/YaBB.pl?num=1524236298/4#4

Populating it once when the application starts should be enough.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
ErikJ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 26th, 2019
Re: Setting KeyLabels best practice
Reply #2 - Apr 1st, 2019 at 12:36pm
Print Post  
That example is for WPF, I am using Winforms.. Not sure that is the reason but the KeyInterop is undefined for me.

Code (C++)
Select All
int KeyCode(Key key)
{
	return KeyInterop.VirtualKeyFromKey(key);
}  



Is the SetKeyLabels path correct for me even if I have AutoFill property turned off? Basically I am looking for a way to update some of the non-character/digit keys such as Shift, Space, Back, Tab, etc when switching to Spanish from English. I do have some custom keys as well as changed text on Enter button to "Submit" which also needs to be translated.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2160
Joined: Oct 19th, 2005
Re: Setting KeyLabels best practice
Reply #3 - Apr 1st, 2019 at 7:11pm
Print Post  
In WinForms the integral value of Keys enum elements matches their virtual key code, so you could assign key labels like this -

Code
Select All
// using Keys = System.Windows.Forms.Keys;

var bg = new CultureInfo("bg-BG");
var en = new CultureInfo("en-US");

kb.SetKeyLabels(bg, new []
    {
        new KeyLabels { VirtualKey = (int)Keys.Q, Lower = "Яя"},
    });
kb.SetKeyLabels(en, new[]
    {
        new KeyLabels { VirtualKey = (int)Keys.Q, Lower = "Qq"},
    });
 



Sadly, SetKeyLabels supports only RegularKey and NumPadKey labels at this time, while Shift, Back, Space etc are instances of SpecialKey. We'll have in mind extending it to support the latter for next release. For time being you could save two different versions of your custom layout for the two languages, using the default name suggested by Keyboard Creator that includes a layout id, and then place them in a folder pointed by keyboard's LayoutsFolder property. That should load them dynamically when the language changes. Alternatively you could alter the layouts dynamically like this -

Code
Select All
var layout = KeyboardLayout.Create("KeyLayout_UserReg.xml");
var newLayout = new KeyboardLayout();
foreach (var key in layout.Keys)
{
    var sk = key as SpecialKey;
    if (sk != null && sk.VirtualKey == (int)Keys.Space)
    {
        var s2 = (SpecialKey)sk.Clone();
        s2.Content = "Интервал";
        newLayout.Keys.Add(s2);
    }
    else
    {
        newLayout.Keys.Add(key);
    }
}
kb.TemplateLayout = newLayout; 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
ErikJ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 26th, 2019
Re: Setting KeyLabels best practice
Reply #4 - Apr 4th, 2019 at 9:43pm
Print Post  
Slavcho: your code example of dynamically building the layout works great for my solution!

Though one issue I noticed is the detection of the Shift key never hits.  It may be related to there being two Shifts (left/right).  All the other special keys get caught in the VirtualKey comparison.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2160
Joined: Oct 19th, 2005
Re: Setting KeyLabels best practice
Reply #5 - Apr 5th, 2019 at 10:00am
Print Post  
Does it work if you call Key.Shift.Equals(key) instead of checking the key code?
  
Back to top
 
IP Logged
 
ErikJ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 26th, 2019
Re: Setting KeyLabels best practice
Reply #6 - Apr 5th, 2019 at 12:36pm
Print Post  
Yes that works!
Slavcho wrote on Apr 5th, 2019 at 10:00am:
Does it work if you call Key.Shift.Equals(key) instead of checking the key code?

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint