B4J Question How can I use the win library "user32" ?

vmag

Active Member
Hello everyone! In standard VB, I use this construction:
ASP.net:
Private Declare Function ActivateKeyboardLayout Lib "user32" (ByVal HKL As Long, ByVal flags As Long) As Long
Const kb_lay_ru As Long = 68748313, kb_lay_en As Long = 67699721

Sub Rus()
Dim x As Long
    ' Switch to Russian language
    x = ActivateKeyboardLayout&(kb_lay_ru, 0)
End Sub
 
Sub En()
Dim x As Long
    ' Switch to English
    x = ActivateKeyboardLayout&(kb_lay_en, 0)
End Sub
The functions switch the input language to Russian and English respectively.
Is it possible to implement something like this on b4j under windows?
 

John Naylor

Active Member
Licensed User
Longtime User
You could use a system call via the jshell library and run the chcp command.

[edit] my apologies for not giving a specific example. I'm sat at a clients in between meetings and checking the forums on my phone.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0

vmag

Active Member
You could use a system call via the jshell library and run the chcp command.

[edit] my apologies for not giving a specific example. I'm sat at a clients in between meetings and checking the forums on my phone.
This is too difficult for me, I downloaded the library, but I have no idea what chcp command is and where to insert it... if you have time, please make a simple example: one form, one button on it, which makes the input language English, thank you for your answer
 
Upvote 0

vmag

Active Member
I have already received the following result from the responses of this post:
B4X:
Sub Button1_Click
    Dim shl As Shell
    Dim langs As String
    langs = "en-US, Ru"
    shl.InitializeDoNotHandleQuotes("shl", "powershell", Array($"Set-WinUserLanguageList -LanguageList ${langs} -Force"$))
    shl.RunSynchronous(-1)
End Sub

Sub Button2_Click
    Dim shl As Shell
    Dim langs As String
    langs = "Ru, en-US"
    shl.InitializeDoNotHandleQuotes("shl", "powershell", Array($"Set-WinUserLanguageList -LanguageList ${langs} -Force"$))
    shl.RunSynchronous(-1)
End Sub
- Button 1 Makes the first input language English, the second Russian
- Button 2, on the contrary, makes the first input language Russian, and the second English
But this is a little different, we already have only these two languages in the country, I need a little different:
- You need to make button 1 the current input language English, and button 2 made the current input language Russian
how do I implement this ?
 
Upvote 0

vmag

Active Member
I think this is a very simple question, but I can't formulate it correctly, I'll try again:
- there is a form with text fields
- in some fields you need to enter text only in English, in other fields only in Russian
- and I want that when the focus field is received, the desired input language for this field is automatically set and this is only necessary for b4j and only under windows
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
This is too difficult for me, I downloaded the library, but I have no idea what chcp command is and where to insert it... if you have time, please make a simple example: one form, one button on it, which makes the input language English, thank you for your answer

@Erel's post covers it really although the example shows English and Hebrew (and uses a better technique than my original suggestion).

To mimic your VB code.....


B4X:
Sub Rus()

    ' Switch to Russian language

    Dim lang As String = "ru, EN-US"

    Dim shl As Shell

    shl.InitializeDoNotHandleQuotes("shl", "powershell", Array($"Set-WinUserLanguageList -LanguageList ${lang} -Force"$))

    shl.RunSynchronous(-1)

End Sub

Sub En()
    ' Switch to English

    Dim lang As String = "EN-US, ru"

    Dim shl As Shell

    shl.InitializeDoNotHandleQuotes("shl", "powershell", Array($"Set-WinUserLanguageList -LanguageList ${lang} -Force"$))

    shl.RunSynchronous(-1)

End Sub

A list of ISO codes can be found here if you want to use a different keyboard layout to English US.
 
Last edited:
Upvote 0

vmag

Active Member
.........
To mimic your VB code.....
........
Please note, your code is the same as mine above, only instead of Rus and En button1 and button2 and I wrote that this does not work.
dontwork.jpg


This example simply swaps the input languages, but does not select the current input language for this form. If I click the Rus button, the text in the field will still be entered in English, if the input language was English before
 

Attachments

  • lang1.zip
    2.2 KB · Views: 180
Last edited:
Upvote 0

vmag

Active Member
Maybe you need to go another way?
- Let's say I know that I need to switch to English to enter data in field 1
- I need to determine what input language is now
- If not English, then I need to find out what keyboard shortcut is used to switch input languages and simulate pressing this combination...
but it's kind of complicated and it's like getting your right ear out with your left hand over your back
 
Upvote 0

vmag

Active Member
In this video, the question is implemented in VB. You can change the input language of fields by force, but when you get the focus, the desired input language is automatically set (naturally for the entire application)
 
Upvote 0

vmag

Active Member
In principle, some solution has been found. If the focus falls in the Russian text input field, then we do this
B4X:
    Dim lang As String = "ru, RU"
    Dim shl As Shell
    shl.InitializeDoNotHandleQuotes("shl", "powershell", Array($"Set-WinUserLanguageList -LanguageList ${lang} -Force"$))
    shl.RunSynchronous(-1)
and if the field requires entering English text, then we do this
B4X:
    Dim lang As String = "EN-US, en"
    Dim shl As Shell
    shl.InitializeDoNotHandleQuotes("shl", "powershell", Array($"Set-WinUserLanguageList -LanguageList ${lang} -Force"$))
    shl.RunSynchronous(-1)
after entering data, we return either this or that
B4X:
    Dim lang As String = "ru, EN-US"  ' OR "EN-US, ru"
    Dim shl As Shell
    shl.InitializeDoNotHandleQuotes("shl", "powershell", Array($"Set-WinUserLanguageList -LanguageList ${lang} -Force"$))
    shl.RunSynchronous(-1)

If anyone has other ways to solve the issue (without such drastic measures), please share...
 
Upvote 0
Top