Page 1 of 1
Change the active keyboard
Posted: Tue Oct 16, 2018 9:27 am
by miroslav.maričić
СРБ:
Желео бих да урадим следеће:
- Чим се програм стартује да упамти актуелну тастатуру,
- Да постави тастатуру по жељи (на пример, Српска ћирилица),
- Пре изласка из програма да се врати упамћена тастатура.
Надам се да је пост разумљив, пошто сам превео помоћу Гугла
ENG:
I would like to do the following:
- As soon as the program starts to remember the current keyboard,
- Set the keyboard as desired (for example, Serbian Cyrillic),
- Before exiting the program, return the memorized keyboard.
I hope the post is understandable, since I translated it using Google
Re: Change the active keyboard
Posted: Wed Oct 17, 2018 2:12 pm
by miroslav.maričić
Nobody answered my post, it seems that Gugl did not translate well...
Re: Change the active keyboard
Posted: Wed Oct 17, 2018 3:50 pm
by serge_girard
I think I understood your question well but I don't know how to retrieve current keyboard-setting (and save it for resetting).
Maybe Rathi, or someone else, knows?
Serge
Re: Change the active keyboard
Posted: Wed Oct 17, 2018 6:54 pm
by miroslav.maričić
I was trying to do something with the functions GETKEYBOARDLAYOT(), LOADKEYBOARDLAYOUT(), ACTIVATEKEYBOARDLAYOUT(), etc. but without success...
Re: Change the active keyboard
Posted: Wed Oct 17, 2018 7:05 pm
by KDJ
It seems to me, this is possible using WIN API functions in C lang level:
- SystemParametersInfo() with SPI_GETDEFAULTINPUTLANG/SPI_SETDEFAULTINPUTLANG parameter - for get/set default keyboard layout in system,
- ActivateKeyboardLayout() - set keyboard layout only for current process or thread.
I have not tried it yet.
Re: Change the active keyboard
Posted: Wed Oct 17, 2018 10:31 pm
by edk
Code: Select all
#include "hmg.ch"
FUNCTION Main()
Local lReleaseLayout
Public cDefKLID := GetKeyboardLayoutName()
Public nDefHKL := GetKeyboardLayout()
Public cSerbCyrKLID := "00000C1A" // Serbian (Cyrillic) --> http://kbdlayout.info/
DEFINE WINDOW TCRMForm AT 0 , 0 ;
WIDTH 270 HEIGHT 200 ;
TITLE 'KeYb Serbian (Cyrillic)' ;
MAIN ;
ON INIT lReleaseLayout := SetSerbKeybd() ;
ON Release SetDefKeybd( lReleaseLayout )
DEFINE LABEL Label_1
ROW 30
COL 40
WIDTH 120
HEIGHT 20
VALUE "Serbian Cyrillic"
ALIGNMENT Right
END LABEL
DEFINE TEXTBOX cTest
ROW 55
COL 70
WIDTH 120
HEIGHT 24
VALUE ""
END TEXTBOX
DEFINE BUTTON Button_1
ROW 100
COL 80
WIDTH 100
HEIGHT 28
ACTION ThisWindow.Release
CAPTION "Close"
END BUTTON
DEFINE STATUSBAR FONT "MS Shell Dlg" SIZE 7
STATUSITEM HMGVersion()
CLOCK
END STATUSBAR
ON KEY ESCAPE ACTION ThisWindow.Release
END WINDOW
CENTER WINDOW TCRMForm
ACTIVATE WINDOW TCRMForm
Return Nil
************************************************************
FUNCTION SetSerbKeybd()
Local aLayoutList := GetKeyboardLayoutList(), nHKL, lIsLoadedSerbCyrHKL := .F.
IF Upper( cDefKLID ) == Upper( cSerbCyrKLID ) //already serbian cyr layout is active
RETURN .F.
ENDIF
FOR EACH nHKL IN aLayoutList
IF GetKeyboardLayoutName( nHKL ) == Upper( cSerbCyrKLID ) // serbian cyr layout is loaded
lIsLoadedSerbCyrHKL := .T.
ActivateKeyboardLayout( nHKL , 0x00000008)
EXIT
ENDIF
NEXT
IF !lIsLoadedSerbCyrHKL
LoadKeyboardLayout( cSerbCyrKLID, 0x0000001 )
ENDIF
RETURN !lIsLoadedSerbCyrHKL
************************************************************
FUNCTION SetDefKeybd( lReleaseLayout )
ActivateKeyboardLayout( nDefHKL, 0x00000008 )
IF lReleaseLayout
UnLoadKeyboardLayout( cSerbCyrKLID )
ENDIF
RETURN Nil
Re: Change the active keyboard
Posted: Thu Oct 18, 2018 3:01 am
by esgici
Re: Change the active keyboard
Posted: Thu Oct 18, 2018 6:06 am
by miroslav.maričić
I thank Mr. Edk for help. I tried the code he wrote and works perfectly! I've been struggling for a long time and I have not been able to solve this problem. Thank you very much, Mr. edk!