flat assembler
Message board for the users of flat assembler.

Index > Windows > Keyboard layuot

Author
Thread Post new topic Reply to topic
KostX



Joined: 19 Sep 2012
Posts: 38
KostX
Hi for all!

I've a few questions:
How do I get a currently language to displayng?
How do I display that data? I wanna output it into text fotmat than display it in the Editbox.

I'm using this code:

Code:

format PE GUI 4.0

entry start

include 'win32a.inc'

section '.code' code readable executable
; It's variable which keeps a result
LayOut     rb 10

start:

     invoke  GetModuleHandle, 0

     invoke  GetWindowThreadProcessId, eax, 0

     invoke  GetKeyboardLayout, eax

     ; I wanna display the result here! But the MessageBox displays nothing!!!
     invoke  MessageBox,  0, LayOut, 0, 0

exit:
     invoke  ExitProcess, 0

data import

     library kernel32, 'KERNEL32.DLL',\
             user32,   'USER32.DLL'

     include 'api\kernel32.inc'
     include 'api\user32.inc'

end data
    


Halp me, please!
Post 28 Sep 2012, 13:03
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Take a look at this:
Code:
format PE GUI 4.0

entry start

include 'win32w.inc' ; Using Unicode version so LCIDToLocaleName can be used

section '.code' code readable executable
fmt du "Primary Language ID = %d", 13, 10,\
       "SubLanguage ID = %d", 13, 10,\
       "Language name = ""%s""", 0

start:

     invoke  GetModuleHandle, 0

     invoke  GetWindowThreadProcessId, eax, 0

     invoke  GetKeyboardLayout, eax

     movzx   eax, ax
     mov     ecx, eax
     mov     edx, eax

     shr     edx, 10
     and     eax, (1 shl 10) - 1

     mov     [priLang], eax
     mov     [subLang], edx

     invoke  LCIDToLocaleName, ecx, langName, 256, 0

     cinvoke wsprintf, LayOut, fmt, [priLang], [subLang], langName

     ; I wanna display the result here! But the MessageBox displays nothing!!!
     invoke  MessageBox,  0, LayOut, 0, 0

exit:
     invoke  ExitProcess, 0

section '.data' data readable writable
LayOut     rw 256 ; Placed here, in a section with writable permission set
priLang    dd ?
subLang    dd ?
langName   rw 256

data import

     library kernel32, 'KERNEL32.DLL',\
             user32,   'USER32.DLL'

     import kernel32,\
            ExitProcess, 'ExitProcess',\
            GetModuleHandle, 'GetModuleHandleW',\
            LCIDToLocaleName, 'LCIDToLocaleName'
     include 'api\user32.inc'

end data    
Post 28 Sep 2012, 13:48
View user's profile Send private message Reply with quote
KostX



Joined: 19 Sep 2012
Posts: 38
KostX
Thank you, LocoDelAssembly. I thinking that is!
But I have a new problam. Whan I executing my application i've an error: Entry point into procedure "LCIDToLocaleName" not found. This is due to the fact that I live in Ukraine and I have a different version of the Shell32.dll??? We're using ANSI coding.


Last edited by KostX on 28 Sep 2012, 14:27; edited 1 time in total
Post 28 Sep 2012, 14:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17473
Location: In your JS exploiting you and your system
revolution
LCIDToLocaleName was introduced in Vista and Server2008. It you are using XP or below then it won't be available.
Post 28 Sep 2012, 14:27
View user's profile Send private message Visit poster's website Reply with quote
KostX



Joined: 19 Sep 2012
Posts: 38
KostX
Thank you, revolution. I've found. I check my programm in computer with Win8, than it works. I've copied kernel32.dll of Win 8 on my computer.
Now I'm experimenting =)
Post 28 Sep 2012, 14:31
View user's profile Send private message Reply with quote
KostX



Joined: 19 Sep 2012
Posts: 38
KostX
Excuse me, have you a variant for Windows XP?
Post 28 Sep 2012, 16:37
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Sorry, didn't notice that function also needed Vista and later. This code does something different, but seems everything it uses is available in XP:
Code:
LOCALE_SLANGUAGE = 2

format PE GUI 4.0
entry start

include 'win32a.inc'

section '.code' code readable executable
fmt db "Primary Language ID = %d", 13, 10,\
       "SubLanguage ID = %d", 13, 10,\
       "Language = ""%s""", 0

start:

     invoke  GetModuleHandle, 0

     invoke  GetWindowThreadProcessId, eax, 0

     invoke  GetKeyboardLayout, eax

     movzx   eax, ax
     mov     ecx, eax
     mov     edx, eax

     shr     edx, 10
     and     eax, (1 shl 10) - 1

     mov     [priLang], eax
     mov     [subLang], edx

     invoke  GetLocaleInfo, ecx, LOCALE_SLANGUAGE, languageName, 128

     cinvoke wsprintf, message, fmt, [priLang], [subLang], languageName

     invoke  MessageBox,  0, message, 0, 0

exit:
     invoke  ExitProcess, 0

section '.data' data readable writable
message      rb 256 ; Placed here, in a section with writable permission set
languageName rb 128
priLang      dd ?
subLang      dd ?

data import

     library kernel32, 'KERNEL32.DLL',\
             user32,   'USER32.DLL'

     include 'api\kernel32.inc'
     include 'api\user32.inc'

end data    
Still, this only reports the language, not the keyboard layout itself. For instance, I´m currently using an USB Latin American keyboard attached to my notebook, and it is reported this way:
Code:
---------------------------
Error
---------------------------
Primary Language ID = 10

SubLanguage ID = 11

Language = "Spanish (Argentina)"
---------------------------
OK   
---------------------------    
It is correct because in the control panel that is how it is configured, but the layout itself is "Latin American", which is not mentioned there. GetKeyboardLayoutName doesn't work either as it returns the string "0000080A". Apparently you need to use this integer-as-string to lookup into HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\ and access the "Layout Text" value in the Windows registry. Anyone knows an easier method to get the layout name?
Post 28 Sep 2012, 22:01
View user's profile Send private message Reply with quote
KostX



Joined: 19 Sep 2012
Posts: 38
KostX
Thank you, LocoDelAssembly. It works!
Post 29 Sep 2012, 08:45
View user's profile Send private message Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
gymkhana among deprecations and mess,
because LOCALE_SLANGUAGE deprecated for win7
while GetLocalInfo deprecated from Vista. ok
LocoDelAssembly wrote:
...Anyone knows an easier method to get the layout name?
dont know if it works on XP but the following, is ok on Vista
Code:
;--- first get all available HKLs

  GetKeyboardLayoutList,2,hkl_list ;--- i have 0407h and 0409h

;--- then, knowing what your app can manage,0407h and 0409h in my case,
;--- activate the HKL you need for the current process (100h)

  mov eax,dword[hkl_list+4]
  ActivateKeyboardLayout,eax,100h

;--- now getting the layout for the current process, it rets 0409h
;--- hkl for English USA

  xor eax,eax
  GetKeyboardLayout, eax

;--- having it, feed it with LOCALE_SLANGUAGE = 2 for a check
   
  and eax,0FFFFh
  GetLocaleInfo, eax, 2, langname, 128

;---  langname now point to "English (USA)"      

in this way it should return the right string "Latin American"

Cheers,

_________________
⠓⠕⠏⠉⠕⠙⠑
Post 29 Sep 2012, 16:47
View user's profile Send private message Visit poster's website Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
but this works too on Vista,
i set EN 0409h below on the taskbar near the current date, then i start application
Code:
 xor eax,eax
 invoke ActivateKeyboardLayout,eax,100h
 ;-- it return 0407h (German)
 xor eax,eax
 invoke  GetKeyboardLayout, eax
 ;---it returns 0409h (English USA)
    

confirmed on Xp ?

_________________
⠓⠕⠏⠉⠕⠙⠑
Post 29 Sep 2012, 17:26
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.