Показать полную графическую версию : [решено] Переключение раскладки клавиатуры правым SHIFT
Привет, коллеги!
У меня исторически работал сабж с помощью Windows PowerPro, но в 7 эта чудесная функция работать перестала. Можно ли такое реализовать с помощью AutoIt?
Буду признателен за скрипт.
Спасибо!
У меня исторически работал сабж с помощью Windows PowerPro, но в 7 эта чудесная функция работать перестала »
Не тестировал в Win 7, но на XP для этой задачи прекрасно работает SwitchIt (http://www.switchit.ru/).
Можно ли такое реализовать с помощью AutoIt? »
Конечно:
#include <Misc.au3>
Dim (http://www.autoitscript.com/autoit3/docs/keywords.htm#Dim) $hUser32_Dll = DllOpen (http://www.autoitscript.com/autoit3/docs/functions/DllOpen.htm)("User32.dll")
;Задаём языки циклического переключения (в том же порядке в каком они выводятся в списке ниже)
;Можно указывать как коды языков, так и их названия (см. список в функций _OSGetLangString):
Dim (http://www.autoitscript.com/autoit3/docs/keywords.htm#Dim) $sLangs_String = "English_United_States|Russian|Ukrainian"
Dim (http://www.autoitscript.com/autoit3/docs/keywords.htm#Dim) $aLayouts_List = StringSplit (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm)($sLangs_String, "|")
;"Ctrl + Shift + E" для выхода из скрипта
HotKeySet (http://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm)("^+e", "_Exit_Proc")
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(100)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) _IsPressed("A1", $hUser32_Dll) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
_SwitchIt_Proc()
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _SwitchIt_Proc()
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hWnd = WinGetHandle (http://www.autoitscript.com/autoit3/docs/functions/WinGetHandle.htm)("[ACTIVE]")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $nOld_Layout = _WinAPI_GetKeyboardLayout($hWnd)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $nNew_Layout = $nOld_Layout
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aLayouts_List[0]
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aLayouts_List[$i] = $nOld_Layout Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) _OSGetLangString($aLayouts_List[$i]) = $nOld_Layout Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $i = $aLayouts_List[0] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $i = -1
$nNew_Layout = _OSGetLangString($aLayouts_List[$i+1])
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
_WinAPI_LoadKeyboardLayout($nNew_Layout, $hWnd)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _Exit_Proc()
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _WinAPI_LoadKeyboardLayout($sLayoutID, $hWnd)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $WM_INPUTLANGCHANGEREQUEST = 0x50
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) StringLen (http://www.autoitscript.com/autoit3/docs/functions/StringLen.htm)($sLayoutID) <= 3 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $sLayoutID = "00000" & $sLayoutID
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aRet = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll", "long", "LoadKeyboardLayout", "str", $sLayoutID, "int", 0)
DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, "int", $WM_INPUTLANGCHANGEREQUEST, "int", 1, "int", $aRet[0])
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _WinAPI_GetKeyboardLayout($hWnd)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aRet = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll", "long", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", 0)
$aRet = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll", "long", "GetKeyboardLayout", "long", $aRet[0])
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) "0000" & Hex (http://www.autoitscript.com/autoit3/docs/functions/Hex.htm)($aRet[0], 4)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _OSGetLangString($sOSLang_Code=-1)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sOSLang_Code == 0 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) SetError (http://www.autoitscript.com/autoit3/docs/functions/SetError.htm)(1, 0, 0)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aOSLang_Codes = StringSplit (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm)( _
"0436|41c|0401|0801|0c01|1001|1401|1801|1c01|2001|2401|2801|2c01|3001|3401|3801|3c01|4001|042b|042c|0 82c|" & _
"042d|0423|0402|0403|0404|0804|0c04|1004|1404|041a|0405|0406|0413|0813|0409|0809|0c09|1009|1409|1809| 1c09|2009|2409|" & _
"2809|2c09|3009|3409|0425|0438|0429|040b|040c|080c|0c0c|100c|140c|180c|0437|407|0807|0c07|1007|1407|4 08|040d|0439|" & _
"040e|040f|0421|0410|0810|0411|043f|0457|0412|0426|0427|042f|043e|083e|044e|0414|0814|0415|0416|0816| 0418|0419|044f|" & _
"081a|0c1a|041b|0424|040a|080a|0c0a|100a|140a|180a|1c0a|200a|240a|280a|2c0a|300a|340a|380a|3c0a|400a| 440a|480a|4c0a|" & _
"500a|0441|041d|081d|0449|0444|041e|041f|0422|0420|0443|0843|042a", "|")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aOSLang_Strings = StringSplit (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm)( _
"Afrikaans|Albanian|Arabic_Saudi_Arabia|Arabic_Iraq|Arabic_Egypt|Arabic_Libya|Arabic_Algeria|Arabic_M orocco|" & _
"Arabic_Tunisia|Arabic_Oman|Arabic_Yemen|Arabic_Syria|Arabic_Jordan|Arabic_Lebanon|Arabic_Kuwait|Arab ic_UAE|" & _
"Arabic_Bahrain|Arabic_Qatar|Armenian|Azeri_Latin|Azeri_Cyrillic|Basque|Belarusian|Bulgarian|Catalan| Chinese_Taiwan|" & _
"Chinese_PRC|Chinese_Hong_Kong|Chinese_Singapore|Chinese_Macau|Croatian|Czech|Danish|Dutch_Standard|D utch_Belgian|" & _
"English_United_States|English_United_Kingdom|English_Australian|English_Canadian|English_New_Zealand |English_Irish|" & _
"English_South_Africa|English_Jamaica|English_Caribbean|English_Belize|English_Trinidad|English_Zimba bwe|" & _
"English_Philippines|Estonian|Faeroese|Farsi|Finnish|French_Standard|French_Belgian|French_Canadian|F rench_Swiss|" & _
"French_Luxembourg|French_Monaco|Georgian|German_Standard|German_Swiss|German_Austrian|German_Luxembo urg|" & _
"German_Liechtenstei|Greek|Hebrew|Hindi|Hungarian|Icelandic|Indonesian|Italian_Standard|Italian_Swiss |Japanese|" & _
"Kazakh|Konkani|Korean|Latvian|Lithuanian|Macedonian|Malay_Malaysia|Malay_Brunei_Darussalam|Marathi|N orwegian_Bokmal|" & _
"Norwegian_Nynorsk|Polish|Portuguese_Brazilian|Portuguese_Standard|Romanian|Russian|Sanskrit|Serbian_ Latin|" & _
"Serbian_Cyrillic|Slovak|Slovenian|Spanish_Traditional_Sort|Spanish_Mexican|Spanish_Modern_Sort|Spani sh_Guatemala|" & _
"Spanish_Costa_Rica|Spanish_Panama|Spanish_Dominican_Republic|Spanish_Venezuela|Spanish_Colombia|Span ish_Peru|" & _
"Spanish_Argentina|Spanish_Ecuador|Spanish_Chile|Spanish_Uruguay|Spanish_Paraguay|Spanish_Bolivia|Spa nish_El_Salvador|" & _
"Spanish_Honduras|Spanish_Nicaragua|Spanish_Puerto_Rico|Swahili|Swedish|Swedish_Finland|Tamil|Tatar|T hai|Turkish|" & _
"Ukrainian|Urdu|Uzbek_Latin|Uzbek_Cyrillic|Vietnamese", "|")
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aOSLang_Codes[0]
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sOSLang_Code = -1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @OSLang (http://www.autoitscript.com/autoit3/docs/macros.htm#@OSLang) = $aOSLang_Codes[$i] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) "0000" & $aOSLang_Strings[$i]
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sOSLang_Code = $aOSLang_Codes[$i] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) "0000" & $aOSLang_Strings[$i]
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sOSLang_Code = $aOSLang_Strings[$i] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) "0000" & $aOSLang_Codes[$i]
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) SetError (http://www.autoitscript.com/autoit3/docs/functions/SetError.htm)(1, 0, 0)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Это будет циклический переключать раскладку в текущем окне.
Ещё один способ, на этот раз учитываются используемые в системе раскладки клавиатуры, т.е не нужно теперь указывать языки вручную:
#include <Misc.au3>
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $hUser32_Dll = DllOpen (http://www.autoitscript.com/autoit3/docs/functions/DllOpen.htm)("User32.dll")
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $nKey = "A1"
;Получаем список используемых в системе раскладок клавиатуры (для циклического переключения)
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $aLayouts_List = _WinAPI_GetKeyboardLayoutList()
;"Ctrl + Shift + E" для выхода из скрипта
HotKeySet (http://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm)("^+e", "_Exit_Proc")
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(10)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) _IsPressed($nKey, $hUser32_Dll) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) _IsPressed($nKey, $hUser32_Dll)
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(1)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
_SwitchIt_Proc()
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _SwitchIt_Proc()
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hWnd = WinGetHandle (http://www.autoitscript.com/autoit3/docs/functions/WinGetHandle.htm)("[ACTIVE]")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $nOld_Layout = _WinAPI_GetKeyboardLayout($hWnd)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aLayouts_List[0]
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aLayouts_List[$i] = $nOld_Layout Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$i += 1
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $i > $aLayouts_List[0] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $i = 1
_WinAPI_LoadKeyboardLayout($aLayouts_List[$i], $hWnd)
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _Exit_Proc()
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _WinAPI_LoadKeyboardLayout($sLayoutID, $hWnd)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $WM_INPUTLANGCHANGEREQUEST = 0x50
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) StringLen (http://www.autoitscript.com/autoit3/docs/functions/StringLen.htm)($sLayoutID) <= 3 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $sLayoutID = "00000" & $sLayoutID
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aRet = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll", "long", "LoadKeyboardLayout", "str", $sLayoutID, "int", 0)
DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, "int", $WM_INPUTLANGCHANGEREQUEST, "int", 1, "int", $aRet[0])
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _WinAPI_GetKeyboardLayout($hWnd)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aRet = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll", "long", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", 0)
$aRet = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll", "long", "GetKeyboardLayout", "long", $aRet[0])
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) "0000" & Hex (http://www.autoitscript.com/autoit3/docs/functions/Hex.htm)($aRet[0], 4)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _WinAPI_GetKeyboardLayoutList()
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $Ret
$Ret = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)('user32.dll', 'int', 'GetKeyboardLayoutList', 'int', 0, 'ptr', 0)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) (@error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error)) Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) ($Ret[0] = 0) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) SetError (http://www.autoitscript.com/autoit3/docs/functions/SetError.htm)(1, 0, 0)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $tData = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)('ptr[' & $Ret[0] & ']')
$Ret = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)('user32.dll', 'int', 'GetKeyboardLayoutList', 'int', $Ret[0], 'ptr', DllStructGetPtr (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetPtr.htm)($tData))
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) (@error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error)) Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) ($Ret[0] = 0) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) SetError (http://www.autoitscript.com/autoit3/docs/functions/SetError.htm)(1, 0, 0)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $List[$Ret[0] + 1] = [$Ret[0]]
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $List[0]
$List[$i] = Hex (http://www.autoitscript.com/autoit3/docs/functions/Hex.htm)(BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)(DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($tData, 1, $i), 0xFFFF))
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $List
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
madmasles
13-03-2010, 10:57
Creat0R,
У меня не работает;"Ctrl + Shift + E" для выхода из скрипта
HotKeySet("^+e", "_Exit_Proc")Меняю на;"Ctrl+Shift+F12" для выхода из скрипта
HotKeySet("^+{F12}", "_Exit_Proc")Никаких проблем (Windows XP SP3 раскладка по умолчанию русская.)
А переключение отлично работает и память практически не кушает (~5,5 Мб). Класс!:clapping:
Creat0R, если честно, у меня скрипт работает как-то нестабильно - то переключает, то нет.
Но спасибо за наводку на SwitchIt. Когда-то очень-очень давно я ей пользовался по-моему, но потом стал использовать PowerPro, т.к. в двух программах смысла не было.
Вопрос решен, благодарю!
если честно, у меня скрипт работает как-то нестабильно - то переключает, то нет. »
Может какое то другое приложение перехватывает клавишу Shift? а возможно пауза в цикле большая, можно попробовать изменить на Sleep(10).
Это в обеих вариантах такое поведение?
У меня не работает »
Это известная проблема (http://autoit-script.ru/index.php?topic=885.0).
madmasles
13-03-2010, 15:13
Creat0R,
С паузой Sleep(100) у меня стабильнее работают оба варианта, чем с паузой на Sleep(10), но все равно не 100%. Добавил после _SwitchIt_Proc() Beep(500, 100) - оба варианта отрабатывают на 100%. :)
Введите контрольный флаг для блокировки повторных нажатий и не нужно никаких Sleep() и Beep(). И нет необходимости вызывать DllOpen(), он загружается вместе с AutoIt.
Global $Flag = _IsPressed("A1")
...
While 1
Sleep(1)
If _IsPressed("A1") Then
If Not $Flag Then
_SwitchIt_Proc()
$Flag = 1
EndIf
Else
$Flag = 0
EndIf
WEnd
...
Введите контрольный флаг для блокировки повторных нажатий »
Хорошая идея, я как то забыл про этот метод.
нет необходимости вызывать DllOpen(), он загружается вместе с AutoIt »
Есть, об этом сказанно в справке:
Remarks:
If calling this function repeatidly, should open 'user32.dll' and pass in handle.
Чтобы dll'ка не загружалась при каждом вызове.
А ещё лучше так:
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(10)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) _IsPressed("A1", $hUser32_Dll) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) _IsPressed("A1", $hUser32_Dll)
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(10)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
_SwitchIt_Proc()
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Чтобы dll'ка не загружалась при каждом вызове. »
Это описание к функции _IsPressed(), я сомниваюсь, что его когда-нибудь обновляли. Возможно раньше это было так, но вот простой пример, как проверить загружена или нет Dll:
#Include <GDIPlus.au3>
ConsoleWrite('user32.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\user32.dll') & @CR)
ConsoleWrite('shell32.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\shell32.dll') & @CR)
ConsoleWrite('psapi.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\psapi.dll') & @CR)
ConsoleWrite('shlwapi.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\shlwapi.dll') & @CR)
ConsoleWrite('wininet.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\wininet.dll') & @CR)
ConsoleWrite('------------------------------' & @CR)
ConsoleWrite('iphlpapi.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\iphlpapi.dll') & @CR)
$hDll = DllOpen('iphlpapi.dll')
ConsoleWrite('iphlpapi.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\iphlpapi.dll') & @CR)
DllClose($hDll)
ConsoleWrite('iphlpapi.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\iphlpapi.dll') & @CR)
ConsoleWrite('------------------------------' & @CR)
ConsoleWrite('gdiplus.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\gdiplus.dll') & @CR)
_GDIPlus_Startup()
ConsoleWrite('gdiplus.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\gdiplus.dll') & @CR)
_GDIPlus_Shutdown()
ConsoleWrite('gdiplus.dll: ' & _WinAPI_GetModuleHandle(@SystemDir & '\gdiplus.dll') & @CR)
Это описание к функции _IsPressed(), я сомниваюсь, что его когда-нибудь обновляли »
Ну если разработчикам никто об этом не сообщал, то почему они будут обновлять это?
Возможно раньше это было так, но вот простой пример, как проверить загружена или нет Dll »
Не уверен как с этого примера понять, что dll'ку не обязательно открывать, и при этом к ней не будет постоянного обращения (открытие/закрытия), как в случае с FileReadLine например.
Система не загружает в память более одной копии Dll. В любом случае, вот еще один пример:
#Include <WinAPI.au3>
$hProc1 = _WinAPI_GetProcAddress(_WinAPI_GetModuleHandle(@SystemDir & '\user32.dll'), 'GetAsyncKeyState')
$hDll = DllOpen(@SystemDir & '\user32.dll')
$hProc2 = _WinAPI_GetProcAddress(_WinAPI_GetModuleHandle(@SystemDir & '\user32.dll'), 'GetAsyncKeyState')
DllClose($hDll)
$hProc3 = _WinAPI_GetProcAddress(_WinAPI_GetModuleHandle(@SystemDir & '\user32.dll'), 'GetAsyncKeyState')
ConsoleWrite($hProc1 & ' = ' & $hProc2 & ' = ' & $hProc3 & @CR)
Func _WinAPI_GetProcAddress($hModule, $sProc)
Local $Ret = DllCall('kernel32.dll', 'ptr', 'GetProcAddress', 'ptr', $hModule, 'str', $sProc)
If (@error) Or ($Ret[0] = 0) Then
Return SetError(1, 0, 0)
EndIf
Return $Ret[0]
EndFunc ;==>_WinAPI_GetProcAddress
И почему все пытаются выставить значение в Sleep() как можно больше. Sleep(1) более чем достаточно. Вот простой тест:
GUICreate('')
GUISetState()
$Timer = TimerInit()
GUIGetMsg()
ConsoleWrite(TimerDiff($Timer) & @CR)
$Timer = TimerInit()
Sleep(1)
ConsoleWrite(TimerDiff($Timer) & @CR)
Получается, что Sleep(1) тормозит программу в 1000(!) раз больше, чем GUIGetMsg(). А когда используется GUI, Sleep() ведь не ставится.
истема не загружает в память более одной копии Dll »
Да, но скрипт всё ровно при DllCall открывает dll'ку, вызывает в ней функцию, и закрывает, так почему бы просто один раз это не сделать?
почему все пытаются выставить значение в Sleep() как можно больше. Sleep(1) более чем достаточно »
Потому что иногда бывают проблемы без этого, это привычка из старых версий AutoIt'а, где с этим всё было печальней чем теперь ;)
Получается, что Sleep(1) тормозит программу в 1000(!) раз больше, чем GUIGetMsg() »
Почему в 1000, разница только в 10 мс. Хотя странно это, судя по справке (раньше так было по крайней мере), в GUIGetMsg вроде встроена пауза в 10 мс...
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.