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

Change the active keyboard

Post by miroslav.maričić »

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

Re: Change the active keyboard

Post by miroslav.maričić »

Nobody answered my post, it seems that Gugl did not translate well... :?
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Change the active keyboard

Post 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
There's nothing you can do that can't be done...
User avatar
miroslav.maričić
Posts: 7
Joined: Sat Mar 23, 2013 11:38 pm
DBs Used: DBF
Location: Serbia

Re: Change the active keyboard

Post by miroslav.maričić »

I was trying to do something with the functions GETKEYBOARDLAYOT(), LOADKEYBOARDLAYOUT(), ACTIVATEKEYBOARDLAYOUT(), etc. but without success... :(
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: Change the active keyboard

Post 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.
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Change the active keyboard

Post 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
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Change the active keyboard

Post by esgici »

Viva INTERNATIONAL HMG :D
User avatar
miroslav.maričić
Posts: 7
Joined: Sat Mar 23, 2013 11:38 pm
DBs Used: DBF
Location: Serbia

Re: Change the active keyboard

Post 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!
Post Reply