Click here to Skip to main content
11,496,146 members (751 online)
Click here to Skip to main content

Language Input Mode (mainly for hebrew programmers)

, 10 May 2003 97.7K 1.4K 20
How to adjust the input in regard to the desired language mode
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.

Introduction

In my latest project - "Cabnet", I have implemented the language input mode keyboard for restricting the user just to Hebrew typing - the trick isn't to prevent unwanted letters but rather to adjust the keyboard at need.

Details

Developers Target

As the title stated, this article is for mainly Hebrew developers. But in fact, any development which deal with multi-language issue, where the user has to press on Alt+Shift && Caps Lock for language mode input movement, is a legitimate client for the following lines. So, the title is no more than a misled road sign. Then why I did it that way? Local-patriotism? Maybe. But - listen - while most of the time Hebrew programmers must use English as communication tool - for one time only the whole world has to be a hebrewphile but hopefully not a hebrewphobe to read this article.

The problem

As a writer of many client applications - I used to be frustrated from the frequently necessity to change the keyboard input mode from Hebrew to English and vice versa.

Cause

While, usually it is useful to have this option - many times it is just irritating NEEDLESSLY.

Example

Suppose the user has to type his name on edit box and the app's demand is ONLY for Hebrew (or other local language) form.

Solution

  1. Prevent unwanted letters.
  2. Automatically change the keyboard attribute to Hebrew input mode.
You could implement the first solution but it's more wise to fulfill the second approach - as I did.

Demo's Features

 void SetEnglishLanguage()
 void SetLanguageDynamic()
 void SetLocalLanguage()

How it works ?

As you probably know, the windows loop messaging contain three function:
 GetMessage()
 TranslateMessage()
 DispatchMessage()
One role of the TranslateMessage() function is to scan the state of the controls keys - because those states are the trigger factors for manipulation messages.

So, the trick is to hook the message before the translation process - if it is necessary, adjust the language mode by requesting the currently language setting and deactivate the caps lock - thus finally you could launch the built-in translation.

Snippet of code

BOOL CHebrewEdit::PreTranslateMessage(MSG* pMsg) 
{
    switch(pMsg->message) {

    case WM_KEYDOWN:

      ValidateLanguage();
    
    break;
    default:
    break;
};
    return CEdit::PreTranslateMessage(pMsg);
}
Note : the CHebrewEdit name could be replaced by 'CArabicEdit', 'CChineseEdit' or for global name solution 'CLocalEdit'.

void CHebrewEdit::ValidateLanguage()
{
    int ks;
    
    BOOL caps;

    if (IsLanguageDynamic()) return;
    
    if (m_nLanguage == LANG_M_LOCAL)
        
              SendMessage(WM_INPUTLANGCHANGEREQUEST,5,0x40D040D);
        else
    
    if (m_nLanguage == LANG_M_ENGLISH) {
        
              SendMessage(WM_INPUTLANGCHANGEREQUEST,5,0x4090409);
    }

        else ASSERT(FALSE);

        caps = (IsCapsSet() & 0x01);
    
    if (IsEnglishLanguage()) caps=!caps;
    

    if (caps) { // for capslock
        
    keybd_event(VK_CAPITAL,0,0,0);
    keybd_event(VK_CAPITAL,0,KEYEVENTF_KEYUP,0);

    }
    

}

Source Code

My source code implements only the edit box extension, although the code is simple and portable for other windows controls, or even for the whole process by hooking the input process, although it isn't much recommend if you eager to reach speed optimum and robustness (see: SetWindowsHookEx).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

moshe masas
Web Developer
Israel Israel
I'm just a small brain connected to an un-limited
brains network, which lead directly to the top ten
giant minds. Which lead me to the
thought : who am i?

I am just a jerry-built god !

Comments and Discussions

 
GeneralMSDN sample Pin
Fisico5-Dec-05 22:03
memberFisico5-Dec-05 22:03 
QuestionSimpler Method Pin
shmulyeng15-Nov-05 11:48
membershmulyeng15-Nov-05 11:48 
AnswerRe: Simpler Method Pin
Senthil Kumar U18-Jul-06 23:35
memberSenthil Kumar U18-Jul-06 23:35 
AnswerRe: Simpler Method Pin
Nader Al Khatib1-Jul-07 12:10
memberNader Al Khatib1-Jul-07 12:10 
GeneralMake Dos to Win Pin
Y_R27-Mar-05 11:57
memberY_R27-Mar-05 11:57 
GeneralNeed help Pin
percyvimal25-Nov-03 22:08
memberpercyvimal25-Nov-03 22:08 
GeneralActivateKeyboardLayout( ) Pin
Anonymous15-Oct-03 0:13
sussAnonymous15-Oct-03 0:13 
GeneralThe Best Solution For This Matter Pin
Yoavf7-Oct-03 0:09
memberYoavf7-Oct-03 0:09 
GeneralTo moshe masas & Boaz72 and to all Pin
Yoavf6-Oct-03 23:56
memberYoavf6-Oct-03 23:56 
GeneralRe: To moshe masas & Boaz72 and to all Pin
Anonymous13-Oct-03 22:02
sussAnonymous13-Oct-03 22:02 
GeneralRe: To moshe masas & Boaz72 and to all Pin
moshe masas4-Nov-03 4:38
membermoshe masas4-Nov-03 4:38 
GeneralRe: To moshe masas & Boaz72 and to all Pin
Anonymous6-Nov-03 5:34
sussAnonymous6-Nov-03 5:34 
GeneralAlternative Solution Pin
Boaz7214-Aug-03 0:48
memberBoaz7214-Aug-03 0:48 
GeneralRe: Alternative Solution Pin
moshe masas31-Aug-03 1:36
membermoshe masas31-Aug-03 1:36 
GeneralRe: Alternative Solution Pin
boaz7231-Aug-03 9:55
sussboaz7231-Aug-03 9:55 
GeneralRe: Alternative Solution Pin
moshe masas2-Sep-03 4:31
membermoshe masas2-Sep-03 4:31 
GeneralNot working Pin
Didaa14-May-03 20:27
memberDidaa14-May-03 20:27 
GeneralRe: Not working Pin
moshe masas15-May-03 2:45
membermoshe masas15-May-03 2:45 
GeneralRe: Not working Pin
Didaa15-May-03 5:26
memberDidaa15-May-03 5:26 
GeneralRe: Not working Pin
moshe masas15-May-03 6:22
membermoshe masas15-May-03 6:22 
GeneralRe: Not working Pin
Anonymous16-May-03 4:58
sussAnonymous16-May-03 4:58 
GeneralRe: Not working Pin
moshe masas19-May-03 5:39
membermoshe masas19-May-03 5:39 
Generalפרוייקט מצחיק Pin
Bengi12-May-03 2:11
memberBengi12-May-03 2:11 
Generalcabnet ?!? is this a joke !?! Pin
moshe masas12-May-03 4:09
membermoshe masas12-May-03 4:09 
GeneralRe: cabnet ?!? is this a joke !?! Pin
Bengi12-May-03 10:06
memberBengi12-May-03 10:06 
GeneralRe: cabnet ?!? is this a joke !?! Pin
MATT GAY9-Jul-04 10:45
sussMATT GAY9-Jul-04 10:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150520.1 | Last Updated 11 May 2003
Article Copyright 2003 by moshe masas
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid