我想用VB写一个软件,求教高手,功能很简单,但不知道怎么写 20
我想用VB写一个软件,求教高手,功能很简单,但不知道怎么写软件功能:当我打开软件时,会弹出一个text控件,输入一个词组后,按ok,这时小键盘上的1就变成了这个词组,只要...
我想用VB写一个软件,求教高手,功能很简单,但不知道怎么写
软件功能:当我打开软件时,会弹出一个text控件,输入一个词组后,按ok,这时小键盘上的1就变成了这个词组,只要我的软件还开着,不管在什么界面,我按1,都会出现这个词组
简单点说就是:开启软件后,可以把小键盘的1变成一个 词组快捷输入键
今天搞了一天,也没结果,敲得很多东西都是不对,请教高人,这个该如何写,
请教了,请不惜赐教
先感谢了
对了,我用的是vb6,
vb7、.net不太熟,
我的邮箱是
303467342@qq.com
先谢过 展开
软件功能:当我打开软件时,会弹出一个text控件,输入一个词组后,按ok,这时小键盘上的1就变成了这个词组,只要我的软件还开着,不管在什么界面,我按1,都会出现这个词组
简单点说就是:开启软件后,可以把小键盘的1变成一个 词组快捷输入键
今天搞了一天,也没结果,敲得很多东西都是不对,请教高人,这个该如何写,
请教了,请不惜赐教
先感谢了
对了,我用的是vb6,
vb7、.net不太熟,
我的邮箱是
303467342@qq.com
先谢过 展开
展开全部
哪需要APIHOOK那么复杂, 楼下说得太夸张了......
注册一个全局快捷键就可以了
主窗体代码如下
Option Explicit
Dim uVirtKey As Integer
Private Sub Command1_Click()
Dim Modifiers As Long
preWinProc = GetWindowLong(Me.hWnd, GWL_WNDPROC)
SetWindowLong Me.hWnd, GWL_WNDPROC, AddressOf WndProc
uVirtKey = 97 '小键盘的1
RegisterHotKey Me.hWnd, 1, Modifiers, uVirtKey
End Sub
'当程序被关闭时,取消已经注册的热键
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong Me.hWnd, GWL_WNDPROC, preWinProc
UnregisterHotKey Me.hWnd, uVirtKey
End Sub
加入一个标准模块, 代码如下
Option Explicit
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal ID As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal ID As Long) As Long
Public Const WM_HOTKEY = &H312
Public Const GWL_WNDPROC = (-4)
Public preWinProc As Long, MyhWnd As Long, uVirtKey As Long
Public Function WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_HOTKEY Then
If wParam = 1 Then
SendKey
End If
End If
WndProc = CallWindowProc(preWinProc, hWnd, Msg, wParam, lParam)
End Function
Public Sub SendKey()
SendKeys Form1.Text1.Text
End Sub
测试过了, 可以用, 只能是英语, 如果是汉字的话, 可以考虑模拟粘贴
注册一个全局快捷键就可以了
主窗体代码如下
Option Explicit
Dim uVirtKey As Integer
Private Sub Command1_Click()
Dim Modifiers As Long
preWinProc = GetWindowLong(Me.hWnd, GWL_WNDPROC)
SetWindowLong Me.hWnd, GWL_WNDPROC, AddressOf WndProc
uVirtKey = 97 '小键盘的1
RegisterHotKey Me.hWnd, 1, Modifiers, uVirtKey
End Sub
'当程序被关闭时,取消已经注册的热键
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong Me.hWnd, GWL_WNDPROC, preWinProc
UnregisterHotKey Me.hWnd, uVirtKey
End Sub
加入一个标准模块, 代码如下
Option Explicit
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal ID As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal ID As Long) As Long
Public Const WM_HOTKEY = &H312
Public Const GWL_WNDPROC = (-4)
Public preWinProc As Long, MyhWnd As Long, uVirtKey As Long
Public Function WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_HOTKEY Then
If wParam = 1 Then
SendKey
End If
End If
WndProc = CallWindowProc(preWinProc, hWnd, Msg, wParam, lParam)
End Function
Public Sub SendKey()
SendKeys Form1.Text1.Text
End Sub
测试过了, 可以用, 只能是英语, 如果是汉字的话, 可以考虑模拟粘贴
更多追问追答
追问
收到您的邮件了,十分感谢,能不能帮我简单说下模拟粘贴时怎么回事
我在百度里搜到一些,但还是不太懂是什么,昨天下了些win api的资料,正在读,是api里的么?
追答
发邮箱了, 自己看哦, 就改了一点
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
两种方法:计时器和全局键盘消息,留个邮箱吧,唉~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询