Change the active keyboard

HMG Unicode versions 3.1.x related

Moderator: Rathinagiri

Post Reply
User avatar
miroslav.maričić
Posts: 7
Joined: Sat Mar 23, 2013 11:38 pm
DBs Used: DBF
Location: Serbia
Has thanked: 6 times

Change the active keyboard

Post by miroslav.maričić » Tue Oct 16, 2018 9:27 am

СРБ:
Желео бих да урадим следеће:
- Чим се програм стартује да упамти актуелну тастатуру,
- Да постави тастатуру по жељи (на пример, Српска ћирилица),
- Пре изласка из програма да се врати упамћена тастатура.
Надам се да је пост разумљив, пошто сам превео помоћу Гугла :D

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 :D

User avatar
miroslav.maričić
Posts: 7
Joined: Sat Mar 23, 2013 11:38 pm
DBs Used: DBF
Location: Serbia
Has thanked: 6 times

Post by miroslav.maričić » Wed Oct 17, 2018 2:12 pm

Nobody answered my post, it seems that Gugl did not translate well... :?

User avatar
serge_girard
Posts: 2140
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 449 times
Been thanked: 102 times
Contact:

Post by serge_girard » Wed Oct 17, 2018 3:50 pm

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

User avatar
miroslav.maričić
Posts: 7
Joined: Sat Mar 23, 2013 11:38 pm
DBs Used: DBF
Location: Serbia
Has thanked: 6 times

Post by miroslav.maričić » Wed Oct 17, 2018 6:54 pm

I was trying to do something with the functions GETKEYBOARDLAYOT(), LOADKEYBOARDLAYOUT(), ACTIVATEKEYBOARDLAYOUT(), etc. but without success... :(

KDJ
Posts: 212
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 254 times

Post by KDJ » Wed Oct 17, 2018 7:05 pm

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.

edk
Posts: 361
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 102 times
Been thanked: 262 times

Post by edk » Wed Oct 17, 2018 10:31 pm

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

User avatar
esgici
Posts: 4463
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 344 times
Been thanked: 103 times
Contact:

Post by esgici » Thu Oct 18, 2018 3:01 am

Viva INTERNATIONAL HMG :D

User avatar
miroslav.maričić
Posts: 7
Joined: Sat Mar 23, 2013 11:38 pm
DBs Used: DBF
Location: Serbia
Has thanked: 6 times

Post by miroslav.maričić » Thu Oct 18, 2018 6:06 am

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!

Post Reply