这是一个讨厌爬虫的人写的文章,当下的网络,把错误的文章抄的满天下都是
本人亲测win7 win2012可用,废话不多说,上代码
;切换为英文输入法
$hWnd = WinGetHandle("[ACTIVE]") ;$hWnd 为目标窗口句柄,这里设置的是当前活动窗口
$ret = DllCall("user32.dll", "long", "LoadKeyboardLayout", "str", "04090409", "int", 1 + 0)
DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, "int", 0x50, "int", 1, "int", $ret[0])
最大的不同之处 04090409 这才是美式键盘输入法,网上全是
08040804 这是微软输入法,你都没启用,当然调用不上了,而且就算启用了默认还的是中文状态
调用不上对应的输入法,还会使用默认输入法,这就是怎么也切换输入法不成功的原因
想知道是怎么来的?往下看
原理篇:
首先非常感谢这篇文章:也是从一楼回答中找到了成功修改的契机
http://www.autoitx.com/thread-53349-1-1.html
上修改后的完整代码
#Region
#AccAu3Wrapper_Icon= ;程序图标
#AccAu3Wrapper_UseX64=n ;是否编译为64位程序(y/n)
#AccAu3Wrapper_OutFile= ;输出的Exe名称
#AccAu3Wrapper_OutFile_x64= ;64位输出的Exe名称
#AccAu3Wrapper_UseUpx=n ;是否使用UPX压缩(y/n) 注:开启压缩极易引起误报问题
#AccAu3Wrapper_Res_Comment= ;程序注释
#AccAu3Wrapper_Res_Description= ;程序描述
#AccAu3Wrapper_Res_Fileversion=1.0.0.5
#AccAu3Wrapper_Res_FileVersion_AutoIncrement=y ;自动更新版本 y/n/p=自动/不自动/询问
#AccAu3Wrapper_Res_ProductVersion=1.0 ;产品版本
#AccAu3Wrapper_Res_Language=2052 ;资源语言, 英语=2057/中文=2052
#AccAu3Wrapper_Res_LegalCopyright= ;程序版权
#AccAu3Wrapper_Res_RequestedExecutionLevel= ;请求权限: None/asInvoker/highestAvailable/requireAdministrator
#AccAu3Wrapper_Run_Tidy=y ;编译前自动整理脚本(y/n)
#AccAu3Wrapper_Run_Obfuscator=y ;启用脚本加密(y/n)
#Obfuscator_Parameters=/cs=1 /cn=1 /cf=1 /cv=1 /sf=1 /sv=1 ;脚本加密参数: 0/1不加密/加密, /cs字符串 /cn数字 /cf函数名 /cv变量名 /sf精简函数 /sv精简变量
#AccAu3Wrapper_DBSupport=y ;使字符串加密支持双字节字符(y/n) <- 可对中文字符等实现字符串加密
#AccAu3Wrapper_AntiDecompile=y ;是否启用防反功能(y/n) <- 简单防反, 用于应对傻瓜式反编译工具
#EndRegion
#cs ____________________________________
欢迎使用 AutoIt v3 中文版 !
Au3版本: 3.3.14.2
脚本作者: Juck
脚本功能: input_method 输入法测试
更新日志:
联系方式:
#ce _______________脚本开始_________________
Opt("WinTitleMatchMode", 4)
Run("notepad.exe")
Sleep(500)
$hWnd = WinGetHandle("classname=Notepad")
;~ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts
$KeyStr = _GetKeyboardLayout($hWnd)
$KeyName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\" & $KeyStr, "Layout Text")
MsgBox(0, $KeyStr, $KeyName) ;显示默认输入法
LoadKeyboardLayout("04090409", $hWnd) ;设为美式键盘
$KeyStr = _GetKeyboardLayout($hWnd)
$KeyName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\" & $KeyStr, "Layout Text")
MsgBox(0, $KeyStr, $KeyName) ;显示当前修改后的输入法
Func _GetKeyboardLayout($hWnd)
Local $ret = DllCall("user32.dll", "long", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", 0)
$ret = DllCall("user32.dll", "long", "GetKeyboardLayout", "long", $ret[0])
Return Hex($ret[0], 8)
EndFunc ;==>_GetKeyboardLayout
Func LoadKeyboardLayout($sLayoutID, $hWnd)
Local $WM_INPUTLANGCHANGEREQUEST = 0x50
Local $ret = DllCall("user32.dll", "long", "LoadKeyboardLayout", "str", $sLayoutID, "int", 1 + 0)
DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, "int", $WM_INPUTLANGCHANGEREQUEST, "int", 1, "int", $ret[0])
EndFunc ;==>LoadKeyboardLayout
好了,这里再说下思路问题,你电脑有搜狗什么的吧,有输入法管理器吧,别说不知道,再不知道百度去吧
利用输入法管理器 修改默认输入法 ,用这个程序弹窗输入法的代码,这才是真的代码,不在注册表里,查资料说输入法在
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts
反正我是没有找到04090409 但弹出的窗口是【注意弹窗标题!】
看到
MsgBox(0, $KeyStr, $KeyName) ;显示默认输入法
MsgBox(0, $KeyStr, $KeyName) ;显示当前修改后的输入法
这两行了吧,这两行就是核心
想用什么输入法,自己确定输入法代码,就像这 04090409 找谁说理去?
总结
1、用输入法管理器,取默认输入法,配合这个程序修改
2、输入法代码自己确定!尤其不要信网上抄的漫天都是的文章,都是蜘蛛乱爬回来的!只能信一部分!
zhangbest5个人原创,转载请注明,谢谢!