如何实现ctrl+n+m 响应一个程序?请教高手

romancetour 2001-09-12 07:12:53
在KEY。。。里面,
...全文
99 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eastunfail 2001-09-13
  • 打赏
  • 举报
回复
是不是很复杂?我原来为我写的程序编写了一个运行库,内建几百多个函数,其中就包括你要的
mch2000 2001-09-12
  • 打赏
  • 举报
回复
可以用sendKeys(^nm)来响应即可。
sundayboys 2001-09-12
  • 打赏
  • 举报
回复
呵呵,写错了,是RegisterHotKey。
The RegisterHotKey function defines a system-wide hot key.

BOOL RegisterHotKey(
HWND hWnd, // handle to window
int id, // hot key identifier
UINT fsModifiers, // key-modifier options
UINT vk // virtual-key code
);
Parameters
hWnd
[in] Handle to the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop.
id
[in] Specifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier.
fsModifiers
[in] Specifies keys that must be pressed in combination with the key specified by the nVirtKey parameter in order to generate the WM_HOTKEY message. The fsModifiers parameter can be a combination of the following values. Value Meaning
MOD_ALT Either ALT key must be held down.
MOD_CONTROL Either CTRL key must be held down.
MOD_SHIFT Either SHIFT key must be held down.
MOD_WIN Either WINDOWS key was held down. These keys are labeled with the Microsoft Windows logo.


vk
[in] Specifies the virtual-key code of the hot key.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

tg123 2001-09-12
  • 打赏
  • 举报
回复
'按ctrl+F1运行记事本

'm1.bas
Declare Function RegisterHotKey Lib "user32" (ByVal Hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Declare Function UnregisterHotKey Lib "user32" (ByVal Hwnd As Long, ByVal id As Long) As Long
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
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetWindow Lib "user32" (ByVal Hwnd As Long, ByVal wCmd As Long) As Long

Declare Function SetWindowPos Lib "user32" (ByVal Hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Const GWL_WNDPROC = (-4)
Public Const WM_HOTKEY = &H312

Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const VK_F1 = &H70
Public Const VK_F2 = &H71
Public Const VK_F3 = &H72
Public Const VK_F4 = &H73
Public Const VK_F5 = &H74
Public Const VK_F6 = &H75
Public Const VK_F7 = &H76
Public Const VK_F8 = &H77
Public Const VK_F9 = &H78
Public Const VK_F10 = &H79
Public Const VK_F11 = &H7A
Public Const VK_F12 = &H7B
Public Const VK_END = &H23

Public Oldproc As Long

Public Sub Dof(Index As Integer)
If Index = 0 Then Shell "notepad.exe", vbNormalFocus
End Sub

Public Function MyWindowProc(ByVal Hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If iMsg = WM_HOTKEY Then Dof (wParam)
MyWindowProc = CallWindowProc(Oldproc, Hwnd, iMsg, wParam, lParam)
End Function

Sub RegK(Hwnd As Long)
RegisterHotKey Hwnd, 0, MOD_CONTROL, VK_F1
End Sub

Sub UnRegK(Hwnd As Long)
Dim ret As Long, i As Integer
For i = 0 To 20
ret = UnregisterHotKey(Hwnd, i)
Next i
End Sub
'------end of m1.bas


'form1
Private Sub Form_Load()
If App.PrevInstance = True Then
Call MsgBox("Running")
End
Exit Sub
End If

RegK Form1.Hwnd
Oldproc = SetWindowLong(Form1.Hwnd, GWL_WNDPROC, AddressOf MyWindowProc)
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnRegK Form1.Hwnd
Oldproc = SetWindowLong(Form1.Hwnd, GWL_WNDPROC, Oldproc)
End
End Sub


romancetour 2001-09-12
  • 打赏
  • 举报
回复
高手,能详细点吗?
多谢
sundayboys 2001-09-12
  • 打赏
  • 举报
回复
RegistryHotKey

7,788

社区成员

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

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