紧急求助!!!大神们进来看看吧
我现在需要用VB做一个软件,功能是屏蔽输入法的软键盘(比如王码五笔的软键盘),各种方法都可以,只要用不了软键盘就成(但输入法可以照用) 该如何做,大神们给个思路吧。。。。泪奔了 泪奔了
这…………
目的是什么啊……
目的说来话长,主要是给工厂控制机器的电脑用的,大概是防止生产线的操作员误操作,总之能实现就OK啊,大神有木有啥办法啊,思路也行啊,大方向也行啊 这个有点难度,要实现禁用,可能还真的不好办。
不知道你是想禁用所有程序的(也就是系统中运行的任意程序)输入法软键盘,还是只针对自己的程序?
如果是处理自己的程序,也许可以通过HOOK来解决(只要发现打开了软键盘,立即发消息关闭它)。
但要用这种方法来处理第三方程序,可能效果不太好。
我想这样,比如就拿王码五笔来说, 我程序一直检测王码五笔进程出现没有,如果出现了,干脆一直循环发消息来关闭软件盘行吗? 还有 我在网上查了几个 关于输入法的API ,不知道这几个API 可以设置输入法的取消软件盘吗?
GetKeyboardLayoutList
ImmGetDescription
ImmIsIME
ActivateKeyboardLayout
GetKeyboardLayout
兄弟你看可以不?
万分感谢 是针对的第三方程序 也许换个思路,查找和关闭软键盘的窗口更好。等它处理了按键发出键盘消息的时候,你已经很难分辨它的来源。 找到一个比较简单的方法来实现: 只要发现打开了软键盘,就把它的窗口隐藏!
(窗口被隐藏了,自然就无法操作软件盘)
新建一个 标准EXE工程。
然后: 把 Form1移除,再添加一个标准模块、一个类模块(类名: claAtom)。
代码如下:
' 标准模块代码:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function ShowWindow Lib "User32" (ByVal hWnd As Long, ByVal nCmd As Long) As Long
Private Declare Function GetKeyState Lib "User32" (ByVal nVirtKey As Long) As Integer
Private Declare Function FindWindowEx Lib "User32" Alias "FindWindowExW" ( _
ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As Long, ByVal lpsz2 As Long) As Long
Private Const ATOM_TEXT As String = "SoftKBD_Surveillant"
Private Const SOFTKBDCLASS As String = "SoftKBDClsC1"
Private Sub Main()
Dim objAtom As claAtom
Dim lpSKclass As Long
Dim lHWnd As Long
' 用全局原子实现单实例运行
Set objAtom = New claAtom
If (Not objAtom.getAtom(ATOM_TEXT)) Then Exit Sub
lpSKclass = StrPtr(SOFTKBDCLASS)
Do
lHWnd = FindWindowEx(0, 0, lpSKclass, 0)
Do
If (0 = lHWnd) Then
Exit Do
Else
Call ShowWindow(lHWnd, 0)
Exit Do
End If
lHWnd = FindWindowEx(0, lHWnd, lpSKclass, 0)
Loop
' 按 F12 结束程序(实际编译exe时,你可以去掉)
If (&H8000 And GetKeyState(vbKeyF12)) Then Exit Do
DoEvents
Call Sleep(10) ' 可以用5到20ms 。时间太短没必要,太长反应慢了。
Loop
End Sub
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
' 类模块代码: (注意类名: claAtom)
Option Explicit
' 利用“全局原子”防止程序重复运行
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" ( _
ByVal AtomName As String) As Integer
Private Declare Function GlobalFindAtom Lib "kernel32" Alias "GlobalFindAtomA" ( _
ByVal AtomName As String) As Integer
Private Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal AtomName As Integer) As Integer
Private Atom As Integer
Public Function getAtom(AtomName As String) As Boolean
Atom = 0
If (GlobalFindAtom(AtomName) = 0) Then Atom = GlobalAddAtom(AtomName)
getAtom = Atom
End Function
Private Sub Class_Terminate()
If (Atom) Then Call GlobalDeleteAtom(Atom)
End Sub
补充:VB , 基础类