请问如何截获汉字输入?请各位大侠多帮忙,谢谢!

sky100 2001-11-03 02:33:23
我现在已经可以截获键盘的按键,但我想实现截获汉字的输入,例如每用输入法输入一个汉字,我的程序就可以自动捕获这个汉字,因为每个汉字的输入都需要按几次键盘,但按几次是不固定的,所以用截获键盘的方法是不行的,请大家多多帮忙!分不够还可以再给,谢谢大家。
...全文
331 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bardo 2002-01-30
  • 打赏
  • 举报
回复
I think that then source code of VC++ about IME is useful for u to resolution this problame, So please study the source code of the IME.
If you have not, please go:
http://www.csdn.net/expert/topic/503/503993.shtm
wxm322000 2002-01-07
  • 打赏
  • 举报
回复
gggg
sky100 2002-01-07
  • 打赏
  • 举报
回复
巴顿兄,这个问题重点不在全局钩子,全局钩子很久以前我就已经用了,重要的是全局钩子无法在richedit里截获汉字,因为根本没有相应的消息,当然,解决这个问题必须要熟悉windows系统的体制方面的一些细节,对vb的知识的要求到很少。谢谢


wishyoulikenet(st)兄,您的建议很有道理,不过我是要对整个系统进行操作控制,所以要截获光标的位置实现起来可能有点问题,我会试试的,谢谢。
wishyoulikenet 2002-01-07
  • 打赏
  • 举报
回复
我的想法是光标是在不停的移动,你可以记录光标移动前和移动后的位置,然后取出这个
字符,再判断它是不是汉字。
Bardo 2002-01-07
  • 打赏
  • 举报
回复
你可以试试全局的钩子:

Here is a simple example that works for every control I have tried to use it on.
1. Start a new project
2. Add a command button to the form
3. Paste this code into the form
4. Run it
5. move mouse over and off the command button


option Explicitprivate
Declare Function SetCapture Lib "user32" (byval hwnd as Long) as Longprivate Declare Function ReleaseCapture Lib "user32" () as Long
'Code:
'Put this code in MouseMove event. In this example, I put a

'CommandButton on a

'form with the name Command1

private Sub Command1_MouseMove(Button as Integer, Shift as Integer, X _as Single, Y as Single)

static CtrMov as Boolean

static Counter as Long

Counter = Counter + 1

With Command1

'Change this

'Command1

' to your control name

If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) then
ReleaseCapture

CtrMov = false

Command1.BackColor = &HFF&

Command1.Caption = " Not Over " & Counter

Command1.Refresh

'Put here your code to LostMouseFocus

'for example:

me.print "LostMouseFocus"

else

SetCapture .hwnd

If CtrMov = false then

' do this only once per "over"

CtrMov = true

Command1.BackColor = &HFFFFFF

Command1.Caption = " Over " & Counter

Command1.Refresh

'Put here your code to GetMouseFocus

'for example:

me.print "GetMouseFocus"

End If

End If

End With

End Sub


'form
option Explicit
private Sub Form_Load()
hHook = SetWindowsHookEx(WH_KEYBOARD, _
AddressOf KeyboardProc, _
0&, _
App.ThreadID)
End Sub
private Sub Form_Unload(Cancel as Integer)
Call UnhookWindowsHookEx(hHook)
End Sub

'module
option Explicit
public Declare Function CallNextHookEx Lib "user32" _
(byval hHook as Long, _
byval nCode as Long, _
byval wParam as Long, _
byval lParam as Long) as Long
public Declare Function UnhookWindowsHookEx Lib "user32" _
(byval hHook as Long) as Long
public Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" _
(byval idHook as Long, _
byval lpfn as Long, _
byval hmod as Long, _
byval dwThreadId as Long) as Long
public Const WH_KEYBOARD = 2
public hHook as Long
public Function KeyboardProc(byval nCode as Long, _
byval wParam as Long, _
byval lParam as Long) as Long
Dim Temp as string
If nCode >= 0 then
Temp = Chr(wParam)
End If
KeyboardProc = CallNextHookEx(hHook, nCode, wParam, lParam)
End Function
sky100 2001-11-29
  • 打赏
  • 举报
回复
810303(810303),我要截获整个系统的汉字输入,你的函数好像跟我没什么关系。 
810303 2001-11-27
  • 打赏
  • 举报
回复
先来个函数:
private function coninput(para_key as integer,para_constr as string)
dim sconstr as string
sconstr=ucase(para_constr)+chr(13)+chr(8)+chr(27)
if instr(1,sconstr,ucase(chr(para_key)),vbtextcompare)=0 then
coninput=0
else
coninput=para_key
end if
end function
在控件的keypress事件中加入:
private sub text1_keypress(...)
keyascii=coninput(keyascii,"123...")
end sub
“123...”为要想被允许输入的字(仅限E文)
不知是否符合要求
810303 2001-11-27
  • 打赏
  • 举报
回复
先来个函数:
private function coninput(para_key as integer,para_constr as string)
dim sconstr as string
sconstr=ucase(para_constr)+chr(13)+chr(8)+chr(27)
if instr(1,sconstr,ucase(chr(para_key)),vbtextcompare)=0 then
coninput=0
else
coninput=para_key
end if
end function
在控件的keypress事件中加入:
private sub text1_keypress(...)
keyascii=coninput(keyascii,"123...")
end sub
“123...”为要想被允许输入的字(仅限E文)
不知是否符合要求
sky100 2001-11-20
  • 打赏
  • 举报
回复
gameboy999(我心迷茫),很遗憾,在richedit里,输入汉字时,连wm_char都没有,不信你到word里试试。
gameboy999 2001-11-20
  • 打赏
  • 举报
回复
就用WM_CHAR来判断,大于128的一般都是全角字符。
AFIHA 2001-11-12
  • 打赏
  • 举报
回复
我也UP一下
sky100 2001-11-07
  • 打赏
  • 举报
回复
NowCan(能量、激情、雨水、彩虹——雷雨云),好像richbox控件不用wm_ime_char发汉字。

感谢你如此帮助!谢谢!
NowCan 2001-11-07
  • 打赏
  • 举报
回复
终于被我搞定,原来要用WH_CALLWNDPROC钩子。但是还有问题,记事本里可以截获,但IE和WORD里就不行。
NowCan 2001-11-07
  • 打赏
  • 举报
回复
就是WM_IME_CHAR!
sky100 2001-11-06
  • 打赏
  • 举报
回复
NowCan(能量、激情、雨水、彩虹——雷雨云),能否告诉我这个消息是什么?
NowCan 2001-11-06
  • 打赏
  • 举报
回复
用spy++能截获这个消息了,但我的钩子就不行,怪!!!
NowCan 2001-11-06
  • 打赏
  • 举报
回复
还是不行!
JWhiteHorse 2001-11-05
  • 打赏
  • 举报
回复
u~p
sky100 2001-11-05
  • 打赏
  • 举报
回复
argin(猫眉毛),我要监测整个系统的键盘输入,所以恐怕只能用钩子了
Jover 2001-11-05
  • 打赏
  • 举报
回复
u~p
加载更多回复(10)

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧