forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   Библиотеки (http://forum.boolean.name/forumdisplay.php?f=28)
-   -   Переключение раскладки (http://forum.boolean.name/showthread.php?t=6393)

impersonalis 22.09.2008 00:59

Переключение раскладки
 
Код:

;KeyLayoutChanger
;============================
;Взглядом Свиборга приветствуя коллег,
;Импер и Джокер представляют чейнджилку раскладок

;impersonalis (icq 11-999-51-51)
;SBJoker
;============================

;*.decls:
;============================
; .lib "user32.dll"
;Api_GetKeyboardLayoutName%(pwszKLID*):"GetKeyboardLayoutNameA"
;Api_LoadKeyboardLayout%(pwszKLID$,flags%):"LoadKeyboardLayoutA"
;============================

;parameters For api's
;
Const KeyLayoutChanger_KL_NAMELENGTH% = 9-1                      ;length of the keyboardbuffer
Const KeyLayoutChanger_KLF_ACTIVATE% = 1                            ;activate the layout
;the language constants
Dim KeyLayoutChanger_Languages$(5,1)
KeyLayoutChanger_Languages(0,0)=5

KeyLayoutChanger_Languages(1,0)="NL_STD"
KeyLayoutChanger_Languages(1,1)="00000413"

KeyLayoutChanger_Languages(2,0)="EN_US"
KeyLayoutChanger_Languages(2,1)="00000409"

KeyLayoutChanger_Languages(3,0)="DU_STD"
KeyLayoutChanger_Languages(3,1)="00000407"

KeyLayoutChanger_Languages(4,0)="FR_STD"
KeyLayoutChanger_Languages(4,1)="0000040C"

KeyLayoutChanger_Languages(5,0)="RU_RUS"
KeyLayoutChanger_Languages(5,1)="00000419"

Global KeyLayoutChanger_Languages_DEFAULT$

;============================
Function KeyLayoutChanger_SaveDefault()
        KeyLayoutChanger_Languages_DEFAULT=KeyLayoutChanger_GetKbLayout$()
End Function

Function KeyLayoutChanger_GetCode1$(KeyLayoutName$)
        ;RU_RUS -> 00000419
        If KeyLayoutName="DEFAULT"
                Return KeyLayoutChanger_Languages_DEFAULT
        EndIf
        For i=1 To KeyLayoutChanger_Languages(0,0)
                If KeyLayoutChanger_Languages(i,0)=KeyLayoutName
                        Return KeyLayoutChanger_Languages(i,1)
                EndIf
        Next
        Return "-1"
End Function

Function KeyLayoutChanger_GetCode2$(KeyLayoutCode$)
        ;00000419 -> RU_RUS
        For i=1 To KeyLayoutChanger_Languages(0,0)
                If KeyLayoutChanger_Languages(i,1)=KeyLayoutCode
                        Return KeyLayoutChanger_Languages(i,0)
                EndIf
        Next
        Return "-1"
End Function

Function KeyLayoutChanger_GetKbLayout$()
        Local strLocId=CreateBank(KeyLayoutChanger_KL_NAMELENGTH)
        Api_GetKeyboardLayoutName(strLocId)
        Local strLocId_StrMir$=""
        For i=0 To BankSize(strLocId)-1
                strLocId_StrMir=strLocId_StrMir+Chr(PeekByte(strLocId,i))
        Next
        FreeBank(strLocId)
        Return strLocId_StrMir
End Function

Function KeyLayoutChanger_SetKbLayout%(strLocaleId$)
        ;Changes the KeyboardLayout
        ;Returns True when the KeyboardLayout was adjusted properly, False otherwise
        ;If the KeyboardLayout isn't installed, this Function will install it For you

        ;create a buffer
          Local strLocId=CreateBank(KeyLayoutChanger_KL_NAMELENGTH)
        Local strLocId_StrMir$
        Local strLocId_IntMir%
          ;retrieve the current KeyboardLayout
          Api_GetKeyboardLayoutName(strLocId)
        strLocId_StrMir$=""
        For i=0 To BankSize(strLocId)-1
                strLocId_StrMir=strLocId_StrMir+Chr(PeekByte(strLocId,i))
        Next
        ;Check whether the current KeyboardLayout And the
          ;New one are the same
        If strLocId_StrMir = strLocaleId
                ;If they're the same, we Return immediately
                FreeBank(strLocId)
                Return True
        Else
                ;load And activate the layout For the current thread
                    strLocId_IntMir = Api_LoadKeyboardLayout(strLocaleId, KeyLayoutChanger_KLF_ACTIVATE)
                If strLocId_IntMir=0 ;returns Null when it fails
                        FreeBank(strLocId)
                        Return False
                Else ;check again
                        ;retrieve the current layout
                        Api_GetKeyboardLayoutName(strLocId)
                        strLocId_StrMir$=""
                        For i=0 To BankSize(strLocId)-1
                                strLocId_StrMir=strLocId_StrMir+Chr(PeekByte(strLocId,i))
                        Next
                        If strLocId = strLocaleId
                                FreeBank(strLocId)
                                Return True
                        Else
                                FreeBank(strLocId)
                                Return False
                        End If
                End If
        End If
End Function

;demo code:
WaitKey()
KeyLayoutChanger_SaveDefault()
KeyLayoutChanger_SetKbLayout(KeyLayoutChanger_GetCode1("EN_US"))
Print KeyLayoutChanger_GetCode2$(KeyLayoutChanger_GetKbLayout())
WaitKey()
End

Варнинг: необходимы следующие деклсы
Цитата:

.lib "user32.dll"
Api_GetKeyboardLayoutName%(pwszKLID*):"GetKeyboard LayoutNameA"
Api_LoadKeyboardLayout%(pwszKLID$,flags%):"LoadKey boardLayoutA"


Часовой пояс GMT +4, время: 13:17.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Перевод: zCarot