[Gambas-user] How to Change Keyboard Layout

Gianluigi bagonergi at gmail.com
Fri Oct 5 20:05:34 CEST 2018


Hi Jussi,
thank you it work well :-)

Regards
Gianluigi

Il giorno ven 5 ott 2018 alle ore 18:59 Jussi Lahtinen <
jussi.lahtinen at gmail.com> ha scritto:

> "Wait" should never be used in events. Instead you need to use "sleep".
>
> Jussi
>
> On Fri, Oct 5, 2018 at 6:59 PM Gianluigi <bagonergi at gmail.com> wrote:
>
>> I noticed that if we don't add Wait 0.1 *before* SendKeys in the
>> textbox's gotfocus event, we get an error in case of tabs from empty
>> textbox.
>> It is also better to restore the current language on Form_Close event.
>>
>> Regards
>> Gianluigi
>>
>> Il giorno gio 4 ott 2018 alle ore 22:59 Gianluigi <bagonergi at gmail.com>
>> ha scritto:
>>
>>> With activated gb.desktop component:
>>>
>>> Private $bArabian As Boolean
>>>
>>> Public Sub Form_Open()
>>>
>>>   Dim s As String
>>>   Dim hTxt As TextBox
>>>
>>>   hTxt = New TextBox(Me)
>>>   hTxt.Foreground = Color.Transparent
>>>   hTxt.SetFocus
>>>   Me.Show
>>>   Wait 0.1
>>>   ' This combination works with the Italian layout and not with the
>>> American one.
>>>   ' You must find a combination suitable for Arabic.
>>>   Desktop.SendKeys("{[Shift_L]6}")
>>>   Wait 0.1
>>>   s = hTxt.Text
>>>   hTxt.Delete
>>>   If s = "&" Then
>>>     $bArabian = True
>>>     Print "Arabian keyboard"
>>>   Else
>>>     $bArabian = False
>>>     Print "American keyboard"
>>>   Endif
>>>   Print $bArabian
>>>
>>> End
>>>
>>> Public Sub txtArabian_GotFocus()
>>>   ' I don't remember your shortcut to switch keyboard layout, supposing
>>> Ctrl+K
>>>   If $bArabian = False Then
>>>     Desktop.SendKeys("{[Control_L]K}")
>>>     $bArabian = True
>>>   Endif
>>>
>>> End
>>>
>>> Public Sub txtAmerican_GotFocus()
>>>   ' I don't remember your shortcut to switch keyboard layout, supposing
>>> Ctrl+K
>>>   If $bArabian Then
>>>     Desktop.SendKeys("{[Control_L]K}")
>>>     $bArabian = False
>>>   Endif
>>>
>>> End
>>>
>>> Public Sub Form_KeyPress()
>>>
>>>   If Key.Code = Key["K"] And If Key.Control Then
>>>     Print "SWITCH KEYBOARD"
>>>   End If
>>>
>>> End
>>>
>>> Regards
>>> Gianluigi
>>>
>>> Il giorno gio 4 ott 2018 alle ore 21:41 Wael M via User <
>>> user at lists.gambas-basic.org> ha scritto:
>>>
>>>> Thanks Gianluigi and thanks Lee
>>>> you both put some solutions that seems brilliant but I got confused and
>>>> couldn't get an appropriate code out of those
>>>> is my fault I know but don't forget I'm new to Gambas
>>>> so if you please could send me an example for a forum with two
>>>> textboxes each one changes the keyboard language when it get focus, I will
>>>> be profoundly appreciated
>>>>
>>>> thanks again for your valuable time
>>>>
>>>> --------------------------------------------
>>>> On Thu, 10/4/18, T Lee Davidson <t.lee.davidson at gmail.com> wrote:
>>>>
>>>>  Subject: Re: [Gambas-user] How to Change Keyboard Layout
>>>>  To: user at lists.gambas-basic.org
>>>>  Date: Thursday, October 4, 2018, 3:08 PM
>>>>
>>>>  If each box will use a specific
>>>>  layout, you could use a semaphore.
>>>>
>>>>  [code]
>>>>  Public $IsEnglishLayout
>>>>  = True
>>>>
>>>>  Public Sub
>>>>  EnglishTextbox1_GotFocus()
>>>>    If Not
>>>>  $IsEnglishLayout then Destkop.Sendkeys(blah)
>>>>    $IsEnglishLayout = True
>>>>  End
>>>>
>>>>  Public Sub
>>>>  ArabicTextbox1_GotFocus()
>>>>    If
>>>>  $IsEnglishLayout then Destkop.Sendkeys(blah)
>>>>    $IsEnglishLayout = False
>>>>  End
>>>>  [/code]
>>>>
>>>>
>>>>  ___
>>>>  Lee
>>>>
>>>>
>>>>  On 10/3/18 5:27 PM, Wael M
>>>>  via User wrote:
>>>>  > Thank you very much
>>>>  Gianluigi for your help, grazie :)
>>>>  > it
>>>>  worked and could detect my language but not the way I
>>>>  want
>>>>  > let me tell you my story :)
>>>>  > I came to linux from windows and I'm
>>>>  trying to translate an app I did with VB to the
>>>>  corresponding codes in Gambas.
>>>>  > I
>>>>  realized that Gambas is not the same as VB because Linux is
>>>>  not the same as windows
>>>>  > Gambas is just
>>>>  using the same names and following the main rules of VB
>>>>  > in my app I had a form that with three
>>>>  textboxes are filled in Arabic and three are filled in
>>>>  English
>>>>  > when I put the cursor in a
>>>>  textbox it detects the keyboard layout and change it to the
>>>>  desired language
>>>>  > I followed the code
>>>>  you gave but I want to put the event of this code to be when
>>>>  textbox got focus
>>>>  > here is the problem,
>>>>  when I put cursor in the desired textbox, it evokes the code
>>>>  and losing the focus the focus again the textbox making it
>>>>  evoking the same code again and so on
>>>>  >
>>>>  so what I really need is to detect the keyboard layout like
>>>>  reading it directly from linux
>>>>  >
>>>>  > again and again thank you very much for
>>>>  your patience and help
>>>>
>>>>  ----[ Gambas mailing-list is hosted by https://www.hostsharing.net
>>>> ]----
>>>>
>>>>
>>>> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net
>>>> ]----
>>>>
>>>
>> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>>
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181005/829601b3/attachment-0001.html>


More information about the User mailing list