http://files.cnblogs.com/files/liuzhaoyzz/%E5%85%B3%E9%97%AD%E5%85%B6%E4%BB%96%E8%BF%9B%E7%A8%8B%E8%BE%93%E5%85%A5%E6%B3%95IME.rar

新建上面的几个按钮和list,打开记事本或者win32pad,单击向记事本发送消息,程序会按ctrl+空格关闭中文输入法,并发送aaa到记事本。只适用于前台进程。

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_MOUSEACTIVATE = &H21
'以下几个API用于关闭前台进程输入法:
'-------------------------------------------------------------------------------------------------------
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetCurrentThread Lib "kernel32" () As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
Private Declare Function ImmIsIME Lib "imm32.dll" (ByVal hkl As Long) As Long
Private Declare Function ImmGetDescription Lib "imm32.dll" Alias "ImmGetDescriptionA" (ByVal hkl As Long, ByVal lpsz As String, ByVal ubuflen As Long) As Long
'-------------------------------------------------------------------------------------------------------
Private Sub Command1_Click()
'查找记事本句柄
Dim dHwnd As Long
Dim tHwnd As Long
dHwnd = FindWindow("Notepad", vbNullString)
If dHwnd > 0 Then
tHwnd = FindWindowEx(dHwnd, ByVal 0&, "Edit", vbNullString)
End If
SetForegroundWindow tHwnd
SendMessage tHwnd, 33, 0, 0
Sleep 2000 '延迟2秒确保窗口带到前台
'以下代码把前台进程的输入法关闭:
'-------------------------------------------------------------------------------------------------------
Dim hwnd As Long
Dim hCurThread As Long
Dim sCaption As String
Dim sBuffer As String
Dim hCurKBDLayout As Long
hwnd = GetForegroundWindow
sCaption = Space(255)
GetWindowText hwnd, sCaption, 255
If InStr(sCaption, Chr(0)) Then
sCaption = Left(sCaption, InStr(sCaption, Chr(0)) - 1)
End If
hCurThread = GetWindowThreadProcessId(hwnd, ByVal 0&)
hCurKBDLayout = GetKeyboardLayout(hCurThread)
If ImmIsIME(hCurKBDLayout) = 1 Then
sBuffer = Space(255)
RetCount = ImmGetDescription(ByVal hCurKBDLayout, sBuffer, 255)
sBuffer = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
Else
sBuffer = "English(American)"
End If
List1.AddItem "当前窗口标题:" & sCaption
List1.AddItem " 当前输入法: " & sBuffer
If sBuffer <> "English(American)" Then SendKeys "^ "
Sleep 1000 '延迟1秒确保ctrl+空格生效
'-------------------------------------------------------------------------------------------------------
SendKeys "aaa"
' MsgBox pwszKLID
End Sub

Private Sub Command2_Click()
'查找win32pad句柄
Dim dHwnd As Long
Dim tHwnd As Long
dHwnd = FindWindow("win32padClass", vbNullString)
If dHwnd > 0 Then
tHwnd = FindWindowEx(dHwnd, ByVal 0&, "RichEdit20A", vbNullString)
End If
SetForegroundWindow tHwnd '把父窗体带到前台
SendMessage tHwnd, 33, 0, 0 '把子窗体带到前台
Sleep 2000 '延迟2秒确保窗口带到前台
'以下代码把前台进程的输入法关闭:
'-------------------------------------------------------------------------------------------------------
Dim hwnd As Long
Dim hCurThread As Long
Dim sCaption As String
Dim sBuffer As String
Dim hCurKBDLayout As Long
hwnd = GetForegroundWindow
sCaption = Space(255)
GetWindowText hwnd, sCaption, 255
If InStr(sCaption, Chr(0)) Then
sCaption = Left(sCaption, InStr(sCaption, Chr(0)) - 1)
End If
hCurThread = GetWindowThreadProcessId(hwnd, ByVal 0&)
hCurKBDLayout = GetKeyboardLayout(hCurThread)
If ImmIsIME(hCurKBDLayout) = 1 Then
sBuffer = Space(255)
RetCount = ImmGetDescription(ByVal hCurKBDLayout, sBuffer, 255)
sBuffer = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
Else
sBuffer = "English(American)"
End If
List1.AddItem "当前窗口标题:" & sCaption
List1.AddItem " 当前输入法: " & sBuffer
If sBuffer <> "English(American)" Then SendKeys "^ "
Sleep 1000 '延迟1秒确保ctrl+空格生效
'-------------------------------------------------------------------------------------------------------
SendKeys "aaa"
End Sub

Private Sub Command3_Click()
End
End Sub

VB关闭其他进程的输入法的更多相关文章

  1. C# 如何强制关闭WINWORD进程

    private void KillProcess(string processName) //调用方法,传参{try{ Process[] thisproc = Process.GetProcesse ...

  2. C#关闭word进程

    C#关闭word进程 foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName(&q ...

  3. wxPython 对话框关闭后进程无法退出的原因

    wxPython中不要用对话框作为主程序wx.Dialog,这会导致程序关闭后进程无法退出.一种可行的做法是用wx.Frame代替

  4. vb.net 结束进程

    Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ...

  5. VB.net结束进程

    Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ...

  6. windows和linux下关闭Tomcat进程

    windows和linux下解决Tomcat进程 windows下启动Tomcat报错,8080端口号被占用,报错信息如下 两种解决方法,一种是关闭了这个端口号,另外一种是修改Tomcat下的serv ...

  7. Mac 下 查看 使用某端口的进程和关闭该进程的命令

    查看使用某端口的进程 最简单的命令是: lsof -i :端口号 如果要使用管理员权限那么就是: sudo lsof -i :端口号 所以查看 使用某端口号3000的进程可以使用: lsof -i : ...

  8. 彻底关闭Excle进程的几个方法

    之前研究过的问题,最近有朋友问,这里再总结下做一个笔记. 我们在应用程序里面通过创建Excle应用对象打开Excle的情况下,如果不注意几个问题,可能无法彻底关闭Excle进程,来考察下面的几种情况: ...

  9. mac查看当前调用tcp的进程并关闭指定进程

    查看所有tcp进程 监听的端口 lsof -iTCP -sTCP:LISTEN 查看指定端口信息 lsof -i: 关闭指定进程 kill -

随机推荐

  1. [Vuejs] 关于vue-router里面的subRoutes

    刚学习vue,可能有使用不对的地方,希望没有对大家造成困扰! 使用vue-router,为了能够更好的管理.vue文件,需要用到子路由. 先看个错误的例子 routers.js '/company': ...

  2. 非常强大的table根据表头排序,点击表头名称,对其内容排序

    js代码: /** * 通过表头对表列进行排序 * * @param sTableID * 要处理的表ID<table id=''> * @param iCol * 字段列id eg: 0 ...

  3. python中的argparse模块学习

    该模块是python用于解析命令行和参数的标准模块 好文推荐:http://blog.ixxoo.me/argparse.html,不仅域名个性,文章翻译的也很好.推荐

  4. C语言回顾-内存管理和指针函数

    1.fgets()函数 该函数是一个文件操作相关的函数 暂时使用这个函数可以从键盘上接收一个字符串,保存到数组中 char str[50]; 1)scanf("%s",str);/ ...

  5. dd-wrt 定时重连 pppoe 更换ip地址

    因为做代理,IP时常被封的原因,所以,需要每天定时重启路由器,重启路由器影响太大,所以重新拨号是一个更好的选择. 在dd-wrt里面,杀掉pppoe服务进程就可以了,这个进程会自动重新启动,然后就相当 ...

  6. C#如何反射出委托的签名,如何使用反射调用委托

    本文阐述C#中如何反射出委托的签名,假如我们有委托FooDelegate定义如下 delegate double FooDelegate (string param, bool condition); ...

  7. activiti-5.15备份记录

    activiti-5.15用户手册翻译完成 源码下载地址:http://activiti.org/download.html在线浏览地址: http://www.mossle.com/docs/act ...

  8. Linux常用命令小结(续)

    20. mysql mysql --host=127.0.0.1 --port=3306 --database=test --user=test --password=test --default-c ...

  9. Android多媒体--MediaCodec 中文API文档

    *由于工作需要,需要利用MediaCodec实现Playback及Transcode等功能,故在学习过程中翻译了Google官方的MediaCodec API文档,由于作者水平限制,文中难免有错误和不 ...

  10. mybatis 细粒度控制二级缓存

    本文要解决的问题:细粒度控制mybatis的二级缓存.mybatis的二级缓存的问题:当更新SQL执行时只清除当前SQL所在命名空间(namespace)的缓存.如果存在2个命名空间namespace ...