键盘钩子

时间:2024-07-16 16:31:13编辑:揭秘君

有什么杀毒软件能完全防止键盘钩子?

一般情况下,病毒挂钩子是为了截取信息。键盘hook跟键盘输入有关,因此这里的Hook可以实现一些键盘记录等功能,当这里出现Hook,要仔细辨认是否为恶意的键盘记录器,正常程序也可能Hook这里。题主可以下载个杀毒软件,类似腾讯电脑管家或者360,首先用软件全盘查杀下,然后把防火墙以及各种防护措施都打开,这样可以相对提高网络安全系数。在今后的使用过程中,要经常用电脑管家定期清理自己的垃圾,以保持自己的计算机常用常新,使用电脑管家进行有效的拦截、清杀病毒,定期全盘扫描下,来保障你电脑的安全。钩子也分几种,有进程钩子,就是只是捕获某一个特定进程的键盘输入。有程序钩子,只捕获某一个程序的键盘输入。还有全局钩子,可以捕获所有进程或者程序的键盘输入。捕获就是说钩子程序能获取你输入的信息,比方说原来有一些QQ木马就是安装键盘钩子,用于记录你输入的QQ号和密码,又或者一些游戏的盗号程序就是这样的。所以我们在日常使用中一定要定期清理电脑中的垃圾,时常杀毒,养成良好的电脑使用习惯,创造更安全的上网环境。

有什么杀毒软件能完全防止键盘钩子?

你装的是什么杀毒软件呢?

照理说如果杀毒软件工作正常的话,不应该出现这样的情况。我装的是腾讯电脑管家,二合一杀毒那个版本的,最近在想着要不要去试用下8.0最新版本。感觉电脑管家还是很好用的,且不论它的杀毒能力怎么样,单单看它的操作,我就挺喜欢的,电脑小白都能玩转。

另外,我建议,别随便去尝试什么什么明知道是危险的软件,杀毒软件不是用来测试它的杀毒能力的。我一直觉得,无论是什么样的杀毒软件,首先最重要的是防护,其次才是杀毒。保持良好的上网习惯吧,亲。


怎么用c#写的键盘钩子屏蔽键盘按键

c# 钩子屏蔽键盘快捷键


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Hook_Demo
{
public partial class Form1 : Form
{
Win32Hook.Hook hook;
public Form1()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.TopMost = true;
hook = new Win32Hook.Hook();
hook.Start();
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
this.buttonExit.Click+=new EventHandler(buttonExit_Click);
}
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
hook.Close();
}
private void buttonExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}

cs

* 调用:
* Hook hook = new Hook();
* hook.Start();//安装钩子
* hook.Close();//卸载钩子
* 如果需要屏蔽键盘,请在KeyBoardHookProc方法中添加处理
*
* 时 间:2010/7/27 15:56:05
*
* 备注:调用此类必须已管理员身份运行,否则没有权限写入注册表
* 判断是否是管理员代码:(isAdministrator如果为true为系统管理员,false不是管理员)
* AppDomain myDomain = Thread.GetDomain();
* myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
* WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
* bool isAdministrator = myPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32;
namespace Win32Hook
{
public class Hook : IDisposable
{
public delegate int HookProc(int nCode, int wParam, IntPtr lParam);
static int hHook = 0;
public const int WH_KEYBOARD_LL = 13;
HookProc KeyBoardHookProcedure;
[StructLayout(LayoutKind.Sequential)]
public class KeyBoardHookStruct
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
[DllImport("user32.dll")]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);
[DllImport("user32.dll")]
public static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam);
[DllImport("kernel32.dll")]
public static extern IntPtr GetModuleHandle(string name);
public void Start()
{
// 安装键盘钩子
if (hHook == 0)
{
KeyBoardHookProcedure = new HookProc(KeyBoardHookProc);
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyBoardHookProcedure, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
//如果设置钩子失败.
if (hHook == 0)
Close();
else
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", true);
if (key == null)//如果该项不存在的话,则创建该项
key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System");
key.SetValue("DisableTaskMgr", 1, RegistryValueKind.DWord);
key.Close();
}
}
}
public void Close()
{
bool retKeyboard = true;
if (hHook != 0)
{
retKeyboard = UnhookWindowsHookEx(hHook);
hHook = 0;
}
//如果去掉钩子失败.
//if (!retKeyboard) throw new Exception("UnhookWindowsHookEx failed.");
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System", true);
if (key != null)
{
key.DeleteValue("DisableTaskMgr", false);
key.Close();
}
}
public static int KeyBoardHookProc(int nCode, int wParam, IntPtr lParam)
{
if (nCode >= 0)
{
KeyBoardHookStruct kbh = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));
if (kbh.vkCode == 91) // 截获左win(开始菜单键)
return 1;
if (kbh.vkCode == 92)// 截获右win
return 1;
if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control) //截获Ctrl+Esc
return 1;
if (kbh.vkCode == (int)Keys.F4 && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+f4
return 1;
if (kbh.vkCode == (int)Keys.Tab && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+tab
return 1;
if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Shift) //截获Ctrl+Shift+Esc
return 1;
if (kbh.vkCode == (int)Keys.Space && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+空格
return 1;
if (kbh.vkCode == 241) //截获F1
return 1; if (kbh.vkCode == (int)Keys.Control && kbh.vkCode == (int)Keys.Alt && kbh.vkCode == (int)Keys.Delete)
return 1;
if ((int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Alt + (int)Keys.Delete) //截获Ctrl+Alt+Delete
return 1;
if ((int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Shift) //截获Ctrl+Shift
return 1;
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
#region IDisposable 成员
public void Dispose()
{
Close();
}
#endregion
}
}


C#键盘钩子

用C#的名词给你讲...
钩子你可以理解为一个操作系统级的事件....
当你为钩子注册一个函数的时候 也就是在这个事件链上提交了一个委托(函数指针...)
你可以对这个事件参数进行编辑(类似EventArgs获得事件的细节并且给予返回值)
然后手动调用事件链的下一个事件...

其实钩子就是这么一回事...

注册键盘钩子 你就相当于注册了一个事件
这个事件细节里包含着按键去向窗体的句柄 按键的一些细节(键位 按下还是弹起啥啥的 有没有功能键同时按下啥的...)
然后你可以修改细节(嗯 也就是改键功能)
然后返回给窗体去dispatch...

其实理解了就这么简单。
注意的细节就是你的委托要留一个引用 否则会被GC回收掉...


MFC中,窗口响应键盘消息, PreTranslateMessage响应之前必须先按下方向键?

* 猜想可能是焦点的问题。把焦点改变一下!

or 尝试 添加
case WM_GETDLGCODE:
return DLGC_WANTALLKEYS;

对于对话框程序 你必须要注意 WM_GETDLGCODE 消息 。它有时候很有用。
它的返回值意义如下:

#define DLGC_WANTARROWS 0x0001 /* Control wants arrow keys */
#define DLGC_WANTTAB 0x0002 /* Control wants tab keys */
#define DLGC_WANTALLKEYS 0x0004 /* Control wants all keys */
#define DLGC_WANTMESSAGE 0x0004 /* Pass message to control */
#define DLGC_HASSETSEL 0x0008 /* Understands EM_SETSEL message */
#define DLGC_DEFPUSHBUTTON 0x0010 /* Default pushbutton */
#define DLGC_UNDEFPUSHBUTTON 0x0020 /* Non-default pushbutton */
#define DLGC_RADIOBUTTON 0x0040 /* Radio button */
#define DLGC_WANTCHARS 0x0080 /* Want WM_CHAR messages */
#define DLGC_STATIC 0x0100 /* Static item: don't include */
#define DLGC_BUTTON 0x2000 /* Button item: can be checked */


用vb做全局鼠标键盘钩子。。。求助。。

下面是我的《记录鼠标》Form1.frm ,其中也用到了键盘快捷键


VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "记录鼠标"
ClientHeight = 4500
ClientLeft = 45
ClientTop = 435
ClientWidth = 7620
FillColor = &H000000FF&
Icon = "Form1.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4500
ScaleWidth = 7620
StartUpPosition = 3 '窗口缺省
Begin VB.CheckBox Check1
Caption = "操作时是否可以看到本软件"
Height = 255
Left = 4560
TabIndex = 14
Top = 240
Value = 1 'Checked
Width = 3015
End
Begin VB.TextBox Tttex
Alignment = 2 'Center
Appearance = 0 'Flat
Height = 270
Left = 3480
Locked = -1 'True
TabIndex = 13
Text = "00"
Top = 570
Width = 1815
End
Begin VB.CommandButton Command6
Caption = "退出 (&E)"
Height = 375
Left = 6120
TabIndex = 12
Top = 3960
Width = 1335
End
Begin VB.Timer Timer3
Enabled = 0 'False
Interval = 1000
Left = 3600
Top = 4320
End
Begin VB.TextBox Text2
Alignment = 2 'Center
Appearance = 0 'Flat
Height = 270
Left = 3480
TabIndex = 7
Text = "20"
Top = 240
Width = 615
End
Begin VB.CommandButton Command5
Caption = "清空录制 (&Z)"
Height = 375
Left = 3000
TabIndex = 6
Top = 3480
Width = 1335
End
Begin VB.TextBox Text1
Appearance = 0 'Flat
Height = 270
Left = 3480
TabIndex = 5
Text = "D:\鼠标记录.text"
Top = 900
Width = 3975
End
Begin VB.CommandButton Command4
Caption = "打开录制 (&V)"
Height = 375
Left = 3000
TabIndex = 4
Top = 3960
Width = 1335
End
Begin VB.CommandButton Command3
Caption = "保存录制 (&B)"
Height = 375
Left = 4560
TabIndex = 3
Top = 3960
Width = 1335
End
Begin VB.ListBox List1
Height = 4200
ItemData = "Form1.frx":324A
Left = 120
List = "Form1.frx":324C
TabIndex = 2
Top = 120
Width = 2295
End
Begin VB.CommandButton Command2
Caption = "回放录制 (&C)"
Height = 375
Left = 6120
TabIndex = 1
Top = 3480
Width = 1335
End
Begin VB.Timer Timer2
Enabled = 0 'False
Interval = 20
Left = 3000
Top = 4320
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 20
Left = 2400
Top = 4320
End
Begin VB.CommandButton Command1
Caption = "开始录制 (&X)"
Height = 375
Left = 4560
TabIndex = 0
Top = 3480
Width = 1335
End
Begin VB.Label Label5
Caption = "用法"
Height = 1935
Left = 2520
TabIndex = 11
Top = 1440
Width = 4935
End
Begin VB.Label Label4
Caption = "保存地址:"
Height = 255
Left = 2520
TabIndex = 10
Top = 960
Width = 1575
End
Begin VB.Label Label3
Caption = "当前位置:"
Height = 255
Left = 2520
TabIndex = 9
Top = 600
Width = 1455
End
Begin VB.Label Label2
Caption = "回放速度:"
Height = 255
Left = 2520
TabIndex = 8
Top = 300
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'获得鼠标点
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'移到鼠标点
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
'按下键盘
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'鼠标键 - 要求按下
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Private Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Private Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Private Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
'锁定,鼠标和键盘
Private Declare Function BlockInput Lib "user32" (ByVal fEnable As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

'定义


Dim xxx, yyy
Dim SSSDDD As String
Dim CC
'鼠标点类型
Private Type POINTAPI
x As Long
y As Long
End Type
'获得键盘按下
Private Function MyHotKey(vKeyCode) As Boolean
MyHotKey = (GetAsyncKeyState(vKeyCode))
End Function
'获得鼠标键按下
Private Function MyKey(vbKeyLButton) As Boolean
MyKey = GetAsyncKeyState(vbKeyLButton)
End Function

Private Sub Form_Load()
CC = "记录鼠标"
SSSDDD = "0"
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
Label5.Caption = "用法:1 开始录制时按下 A 键停止录制;" & vbCrLf & _
" 2 本软件还可以按下 S 锁定鼠标和键盘,不可移动;" & vbCrLf & _
" 3 本软件还可以按下 D 锁定鼠标和键盘,可移动;" & vbCrLf & _
" 4 每个控制都有一个快捷键,就是每个按钮后括号内。" & vbCrLf & _
vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
" " & App.Title + "( 版本 " & App.Major & "." & App.Minor & "." & App.Revision & " )" '当前版本号是
End Sub

'速度
Private Sub Text2_KeyPress(KeyAscii As Integer)
'文本中只能输入( 0123456789. )数字
If InStr(1, "0123456789", UCase(Chr(KeyAscii)), 1) <= 0 Then KeyAscii = 0
End Sub
Private Sub Text2_Change()
If Text2.Text > 0 Then Timer2.Interval = Text2.Text
End Sub

'读保文件
Private Sub Command3_Click() 'List1 保存 *.txt
Dim fn As Integer, i As Integer
fn = FreeFile
Open Text1.Text For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next
Close #1
MsgBox "成功保存到: " & Text1.Text
End Sub
Private Sub Command4_Click() 'List1 读取 *.txt
List1.Clear '清空
Open Text1.Text For Input As #1
Do While Not EOF(1)
Line Input #1, Temp
List1.AddItem Temp
Loop
Close #1
End Sub

'清空List1
Private Sub Command5_Click()
List1.Clear
End Sub

'回放录制
Private Sub Command2_Click()
ShFu
If List1.ListCount > 0 Then
List1.ListIndex = 1
Form1.Caption = "记录鼠标 - 正在回放"
Timer2.Enabled = True
End If
End Sub
Private Sub Timer2_Timer()
Dim x
List1.ListIndex = List1.ListIndex - 0 + 1
x = Split(List1.Text, "")
SetCursorPos x(0), x(1) '你所需要点的位置
If x(2) = "左" Then ZuoDanJi
If x(2) = "中" Then ZongDanJi
If x(2) = "右" Then YouDanJi
If List1.ListIndex >= List1.ListCount - 1 Then Form1.Caption = "记录鼠标": CC = "停锁记录鼠标": YhFu: Timer2.Enabled = False
End Sub

'鼠标左键点击
Private Sub ZuoDanJi()
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0&, 0&, 0&, 0& '模拟鼠标点击
End Sub
'鼠标中键点击
Private Sub ZongDanJi()
mouse_event MOUSEEVENTF_MIDDLEDOWN Or MOUSEEVENTF_MIDDLEUP, 0&, 0&, 0&, 0& '模拟鼠标点击
End Sub
'鼠标右键点击
Private Sub YouDanJi()
mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0&, 0&, 0&, 0& '模拟鼠标点击
End Sub
'开始录制
Private Sub Command1_Click()
ShFu
Form1.Caption = "记录鼠标 - 正在录制(按下A键停止)"
End Sub
'录制
Private Sub Tttex_Change()
If Form1.Caption = "记录鼠标 - 正在录制(按下A键停止)" Then List1.AddItem Tttex.Text
End Sub

Private Sub Timer1_Timer()
Dim MousG
If MyKey(vbKeyLButton) Then MousG = "左"
If MyKey(vbKeyMButton) Then MousG = "中"
If MyKey(vbKeyRButton) Then MousG = "右"

Dim P1 As POINTAPI
GetCursorPos P1
Tttex.Text = P1.x & "" & P1.y & "" & MousG
MousG = "0"

'快捷键
If MyHotKey(vbKeyA) Then Form1.Caption = "记录鼠标": CC = "停锁记录鼠标": YhFu 'A键盘按下
If MyHotKey(vbKeyX) Then Command1_Click: ShFu
If MyHotKey(vbKeyC) Then Command2_Click: ShFu
If MyHotKey(vbKeyB) Then Command3_Click
If MyHotKey(vbKeyV) Then Command4_Click
If MyHotKey(vbKeyZ) Then Command5_Click
If MyHotKey(vbKeyE) Then Command6_Click
If MyHotKey(vbKeyS) Then SSS: ShFu
If MyHotKey(vbKeyD) Then DDD: ShFu
End Sub

'锁定,鼠标和键盘
Private Sub Timer3_Timer()
If SSSDDD > 0 Then SSSDDD = SSSDDD - 1
If CC = "不可移动" Then Form1.Caption = "记录鼠标 - 锁定鼠标和键盘不可移动 " & SSSDDD & "秒后解锁"
If CC = "可移动" Then Form1.Caption = "记录鼠标 - 锁定鼠标和键盘可移动 " & SSSDDD & "秒后解锁"
If SSSDDD < 1 Then
BlockInput (0)
Form1.Caption = "记录鼠标"
CC = "停锁记录鼠标"
Timer3.Enabled = False
YhFu
End If '恢复
End Sub
Private Sub SSS()
Form1.Caption = "记录鼠标 - 锁定鼠标和键盘,不可移动"
SSSDDD = InputBox("提示", "请问你想锁定多少秒?", "10")
CC = "不可移动"
Timer3.Enabled = True
BlockInput (5) '锁定,不可移动
End Sub
Private Sub DDD()
Form1.Caption = "记录鼠标 - 锁定鼠标和键盘,可移动"
SSSDDD = InputBox("提示", "请问你想锁定多少秒?", "10")
CC = "可移动"
Timer3.Enabled = True
Call Sleep(SSSDDD) '锁定,可移动
End Sub

'操作时是否可以看到本软件
Private Sub ShFu() '
If Check1.Value = 0 Then Form1.Hide '隐藏
End Sub
Private Sub YhFu() '
If CC = "停锁记录鼠标" Then
Form1.Show '显示
CC = "鼠标记录"
End If
End Sub

'删除List1中的一行
Private Sub List1_DblClick() '
List1.RemoveItem List1.ListIndex
End Sub

'退出
Private Sub Command6_Click()
End
End Sub


上一篇:免费瑞星杀毒软件

下一篇:谁有黄的网站