Да... вижу ты не экономил на коде
Код:
#include <Misc.au3>
HotKeySet("{ESC}", "OnAutoItExit")
Global Const $WH_KEYBOARD_LL = 13
Global $hStub_KeyProc = DllCallbackRegister("_Key_Proc", "int", "int;ptr;ptr")
Global $hMod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_KEYBOARD_LL, _
"ptr", DllCallbackGetPtr($hStub_KeyProc), "hwnd", $hMod[0], "dword", 0)
MsgBox(4096, "", "Type anything anywhere and it will appear in the top left corner of the screen.")
While 1
Sleep(100)
WEnd
Func _EvaluateKey_Proc($nKeyCode)
Local $sCapt_Codes, $sEng_Codes, $sEngShift_Codes, $sRus_Codes, $sRusShift_Codes
Local $sUkrCapture_Codes, $sUkr_Codes, $sUkrShift_Codes
Local $aCapture_Codes, $aEng_Codes, $aEngShift_Codes, $aRus_Codes, $aRusShift_Codes
Local $aUkrCapture_Codes, $aUkr_Codes, $aUkrShift_Codes
Local $sSound
Switch $nKeyCode
Case 65 To 90, 48 To 57, 186, 188, 190, 191, 192, 219, 221, 222 ; проверяться будут только нажатия на буквы и цифры
If StringLen($nKeyCode) < 3 Then $nKeyCode = "0" & $nKeyCode
$sCapt_Codes = _
"192,081,087,069,082,084,089,085,073,079,080,219,221,065,083,068,070,071,072,074,075,076," & _
"186,222,090,088,067,086,066,078,077,188,190,191,048,049,050,051,052,053,054,055,056,057"
$sEng_Codes = _
"096,113,119,101,114,116,121,117,105,111,112,091,093,097,115,100,102,103,104,106,107,108," & _
"059,039,122,120,099,118,098,110,109,044,046,047,048,049,050,051,052,053,054,055,056,057"
$sEngShift_Codes = _
"126,081,087,069,082,084,089,085,073,079,080,123,125,065,083,068,070,071,072,074,075,076," & _
"058,034,090,088,067,086,066,078,077,060,062,063,041,033,064,035,036,037,094,038,042,040"
$sRus_Codes = _
"184,233,246,243,234,229,237,227,248,249,231,245,250,244,251,226,224,239,240,238,235,228," & _
"230,253,255,247,241,236,232,242,252,225,254,046,048,049,050,051,052,053,054,055,056,057"
$sRusShift_Codes = _
"168,201,214,211,202,197,205,195,216,217,199,213,218,212,219,194,192,207,208,206,203,196," & _
"198,221,223,215,209,204,200,210,220,193,222,044,041,033,034,185,059,037,058,063,042,040"
$sUkrCapture_Codes = StringReplace($sCapt_Codes, "090", "089")
$sUkr_Codes = _
"046,039,233,246,243,234,229,237,227,248,249,231,245,191,244,179,226,224,239,240,238,235," & _
"228,230,186,255,247,241,236,232,242,252,225,254,048,049,050,051,052,053,054,055,056,057"
$sUkrShift_Codes = _
"146,201,214,211,202,197,205,195,216,217,199,213,175,212,178,194,192,207,208,206,203,196," & _
"198,170,223,215,209,204,200,210,220,193,222,044,041,033,034,185,059,037,058,063,042,040"
$aCapture_Codes = StringSplit($sCapt_Codes, ",")
$aEng_Codes = StringSplit($sEng_Codes, ",")
$aEngShift_Codes = StringSplit($sEngShift_Codes, ",")
$aRus_Codes = StringSplit($sRus_Codes, ",")
$aRusShift_Codes = StringSplit($sRusShift_Codes, ",")
$aUkrCapture_Codes = StringSplit($sUkrCapture_Codes, ",")
$aUkr_Codes = StringSplit($sUkr_Codes, ",")
$aUkrShift_Codes = StringSplit($sUkrShift_Codes, ",")
Switch _WinGetKeyboardLayout(WinGetHandle("[ACTIVE]"))
Case 0409 ;Если раскладка английская
If _IsPressed(10) Then ; если нажата клавиша Shift
_ReplaceKeyCode_Proc($nKeyCode, $aCapture_Codes, $aEngShift_Codes)
Else ; если не нажата клавиша Shift
_ReplaceKeyCode_Proc($nKeyCode, $aCapture_Codes, $aEng_Codes)
EndIf
$sSound = "en.wav"
Case 0419 ;Если расскладка русская
If _IsPressed(10) Then ; если нажата клавиша Shift
_ReplaceKeyCode_Proc($nKeyCode, $aCapture_Codes, $aRusShift_Codes)
Else ; если не нажата клавиша Shift
_ReplaceKeyCode_Proc($nKeyCode, $aCapture_Codes, $aRus_Codes)
EndIf
$sSound = "ru.wav"
Case 0422 ;Если расскладка украинская
If _IsPressed(10) Then ; если нажата клавиша Shift
_ReplaceKeyCode_Proc($nKeyCode, $aUkrCapture_Codes, $aUkrShift_Codes)
Else ; если не нажата клавиша Shift
_ReplaceKeyCode_Proc($nKeyCode, $aUkrCapture_Codes, $aUkr_Codes)
EndIf
$sSound = "ukr.wav"
EndSwitch
ToolTip(Chr($nKeyCode) & " - " & $nKeyCode, 0, 80)
SoundPlay($sSound) ;проигрывать звук при нажатии
Case Else ; если была нажата не буква и не цыфра, то выход из функции
Return
EndSwitch
EndFunc
Func _Key_Proc($nCode, $wParam, $lParam)
Local $aRet, $KEYHOOKSTRUCT
If $nCode < 0 Then
$aRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], "int", $nCode, "ptr", $wParam, "ptr", $lParam)
Return $aRet[0]
EndIf
If $wParam = 256 Then
$KEYHOOKSTRUCT = DllStructCreate("dword;dword;dword;dword;ptr", $lParam)
_EvaluateKey_Proc(DllStructGetData($KEYHOOKSTRUCT, 1))
EndIf
$aRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], "int", $nCode, "ptr", $wParam, "ptr", $lParam)
Return $aRet[0]
EndFunc
;Функция для замены кодов нажатых клавиш с массива
Func _ReplaceKeyCode_Proc(ByRef $nKeyCode, $aSearch_Array, $aReplace_Array)
For $i = 1 To $aSearch_Array[0]
$nKeyCode = StringReplace($nKeyCode, $aSearch_Array[$i], $aReplace_Array[$i])
Next
EndFunc
;функция позволяет узнать язык текущей расскладки клавиатуры
Func _WinGetKeyboardLayout($hWnd)
Local $aRet = DllCall("user32.dll", "long", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", 0)
$aRet = DllCall("user32.dll", "long", "GetKeyboardLayout", "long", $aRet[0])
Return "0000" & Hex($aRet[0], 4)
EndFunc
Func OnAutoItExit()
If $hStub_KeyProc Then DllCallbackFree($hStub_KeyProc)
$hStub_KeyProc = 0
DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0])
If @HotKeyPressed <> "" Then Exit
EndFunc