- Welcome, Guest. Please Login or Register
MindFusion  
  We are soon releasing MindFusion.JavaScript pack. Initial version includes chart, diagram, calendar, map, virtual keyboard, gauge and UI components. Here are the beta version and live demo for anyone interested.  
  HomeHelpSearchLoginRegister   
     
     
   
 
Page Index Toggle Pages: 1 Send Topic Print  
Setting KeyLabels best practice
Read 989 times

ErikJ   Offline
YaBB Newbies
*
Posts: 9
I Love MindFusion!


   
     
 
Setting KeyLabels best practice
Mar 29th, 2019 at 4:36pm
 
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.
 
 
 
IP Logged    
 
     

Slavcho   Offline
YaBB Moderator
*****
Posts: 1718
Gender: male
tech.support


   
     
 
Re: Setting KeyLabels best practice
Reply #1 - Apr 1st, 2019 at 10:37am
 
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
 
 
 
IP Logged    
 
     

ErikJ   Offline
YaBB Newbies
*
Posts: 9
I Love MindFusion!


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

Code (C++):
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.
 
 
 
IP Logged    
 
     

Slavcho   Offline
YaBB Moderator
*****
Posts: 1718
Gender: male
tech.support


   
     
 
Re: Setting KeyLabels best practice
Reply #3 - Apr 1st, 2019 at 8:11pm
 
In WinForms the integral value of Keys enum elements matches their virtual key code, so you could assign key labels like this -

Code:
// 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:
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
 
 
 
IP Logged    
 
     

ErikJ   Offline
YaBB Newbies
*
Posts: 9
I Love MindFusion!


   
     
 
Re: Setting KeyLabels best practice
Reply #4 - Apr 4th, 2019 at 10:43pm
 
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.
 
 
 
IP Logged    
 
     

Slavcho   Offline
YaBB Moderator
*****
Posts: 1718
Gender: male
tech.support


   
     
 
Re: Setting KeyLabels best practice
Reply #5 - Apr 5th, 2019 at 11:00am
 
Does it work if you call Key.Shift.Equals(key) instead of checking the key code?
 
 
 
IP Logged    
 
     

ErikJ   Offline
YaBB Newbies
*
Posts: 9
I Love MindFusion!


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

 
 
 
IP Logged    
 
     
Page Index Toggle Pages: 1 Send Topic Print