[Gambas-user] How to Change Keyboard Layout

Gianluigi bagonergi at gmail.com
Thu Oct 4 01:00:32 CEST 2018


If you get the layout when you open the app, it should work.
Just keep an eye on the switches, e.g:

Private $bItalian 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
  Desktop.SendKeys("{[Shift_L]6}")
  Wait 0.1
  s = hTxt.Text

  hTxt.Delete
  If s = "&" Then
    $bItalian = True
    Print "Italian keyboard"
  Else
    $bItalian = False
    Print "Stranger keyboard"
  Endif
  Print $bItalian

End

Public Sub Form_KeyPress()

  ' I don't remember your shortcut to switch keyboard layout, supposing
Ctrl+K
  If Key.Code = Key["K"] And If Key.Control Then
    $bItalian = Not $bItalian
    Print $bItalian
  End If

End

Regards
Gianluigi

Il giorno mer 3 ott 2018 alle ore 23:28 Wael M via User <
user at lists.gambas-basic.org> ha scritto:

> 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
>
> --------------------------------------------
> On Wed, 10/3/18, Gianluigi <bagonergi at gmail.com> wrote:
>
>  Subject: Re: [Gambas-user] How to Change Keyboard Layout
>  To: "Gambas Mailing List" <user at lists.gambas-basic.org>
>  Date: Wednesday, October 3, 2018, 4:00 PM
>
>  With this code, I'm trying to explain better
>  what I meant to say:
>
>  Public
>  Sub TextBox1_GotFocus()
>
>    Dim s As String
>
>
>  Desktop.SendKeys("{[Shift_L]6}")
>    Wait 0.1
>    s =
>  TextBox1.Text
>    Print s
>
>  Wait 0.1
>    TextBox1.Clear
>    If s = "&" Then
>      Print "Italian keyboard"
>    Else
>      Print
>  "Stranger keyboard"
>    Endif
>
>  End
>
>  Regards
>  Gianluigi
>
>  Il giorno
>  mer 3 ott 2018 alle ore 09:45 Gianluigi <bagonergi at gmail.com>
>  ha scritto:
>  >Lee, I subscribed to the list
>  you mentioned but should I repeate the same thread there or
>  what?
>
>
>
>  >Charlie, thanks for your answer but it didn't
>  exactly did what I want
>
>  >I'm using Ubuntu
>
>  >the code you put gave me this result:
>  XKBLAYOUT=us,ara
>
>  >what I need to get is the current keyboard layout
>
>  >maybe I wasn't clear while putting my problem, so
>  I"ll try to explain more
>
>  >I want to check my current keyboard layout so if its
>  Arabic, it would be changed to English (in >some
>  textboxes) and vices versa.
>
>  >i.e I want to use English in some textboxes and Arabic
>  in others, and I
>  want that to be done >through a code to check Keyboard
>  layout and change
>  it if needed or keep it if no need to change >it
>
>  >thanks in advance to everyone trying to help
>
>  This
>  code that need to do something else, maybe you can direct it
>  to a key that makes you understand if the keyboard is
>  'ara' or 'us'.
>  RegardsGianluigi
>
>
>  ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
>  -----Inline Attachment Follows-----
>
>
>
> ----[ 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/20181004/f4262fc4/attachment-0001.html>


More information about the User mailing list