
DLL虽然会映射到所有进程中,但是其数据段(就是存放全局变量和静态变量的段)在每个进程中都会各自拷贝一份的,除非是共享数据段,所以就出现这种情况。
你的问题就是多进程中如何共享数据,除了共享数据段,还有映射文件,再复杂点,你还可以用消息通知或网络通信去控制另一个进程,或者直接读写另一进程地址空间。
但你这个问题,共享数据段就是最简单也最好用的方法。
下面是我的《记录鼠标》Form1frm ,其中也用到了键盘快捷键
VERSION 500
Begin VBForm Form1
BorderStyle = 1 'Fixed Single
Caption = "记录鼠标"
ClientHeight = 4500
ClientLeft = 45
ClientTop = 435
ClientWidth = 7620
FillColor = &H000000FF&
Icon = "Form1frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4500
ScaleWidth = 7620
StartUpPosition = 3 '窗口缺省
Begin VBCheckBox Check1
Caption = " *** 作时是否可以看到本软件"
Height = 255
Left = 4560
TabIndex = 14
Top = 240
Value = 1 'Checked
Width = 3015
End
Begin VBTextBox Tttex
Alignment = 2 'Center
Appearance = 0 'Flat
Height = 270
Left = 3480
Locked = -1 'True
TabIndex = 13
Text = "0<>0"
Top = 570
Width = 1815
End
Begin VBCommandButton Command6
Caption = "退出 (&E)"
Height = 375
Left = 6120
TabIndex = 12
Top = 3960
Width = 1335
End
Begin VBTimer Timer3
Enabled = 0 'False
Interval = 1000
Left = 3600
Top = 4320
End
Begin VBTextBox Text2
Alignment = 2 'Center
Appearance = 0 'Flat
Height = 270
Left = 3480
TabIndex = 7
Text = "20"
Top = 240
Width = 615
End
Begin VBCommandButton Command5
Caption = "清空录制 (&Z)"
Height = 375
Left = 3000
TabIndex = 6
Top = 3480
Width = 1335
End
Begin VBTextBox Text1
Appearance = 0 'Flat
Height = 270
Left = 3480
TabIndex = 5
Text = "D:\鼠标记录text"
Top = 900
Width = 3975
End
Begin VBCommandButton Command4
Caption = "打开录制 (&V)"
Height = 375
Left = 3000
TabIndex = 4
Top = 3960
Width = 1335
End
Begin VBCommandButton Command3
Caption = "保存录制 (&B)"
Height = 375
Left = 4560
TabIndex = 3
Top = 3960
Width = 1335
End
Begin VBListBox List1
Height = 4200
ItemData = "Form1frx":324A
Left = 120
List = "Form1frx":324C
TabIndex = 2
Top = 120
Width = 2295
End
Begin VBCommandButton Command2
Caption = "回放录制 (&C)"
Height = 375
Left = 6120
TabIndex = 1
Top = 3480
Width = 1335
End
Begin VBTimer Timer2
Enabled = 0 'False
Interval = 20
Left = 3000
Top = 4320
End
Begin VBTimer Timer1
Enabled = 0 'False
Interval = 20
Left = 2400
Top = 4320
End
Begin VBCommandButton Command1
Caption = "开始录制 (&X)"
Height = 375
Left = 4560
TabIndex = 0
Top = 3480
Width = 1335
End
Begin VBLabel Label5
Caption = "用法"
Height = 1935
Left = 2520
TabIndex = 11
Top = 1440
Width = 4935
End
Begin VBLabel Label4
Caption = "保存地址:"
Height = 255
Left = 2520
TabIndex = 10
Top = 960
Width = 1575
End
Begin VBLabel Label3
Caption = "当前位置:"
Height = 255
Left = 2520
TabIndex = 9
Top = 600
Width = 1455
End
Begin VBLabel 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"
Timer1Enabled = True
Timer2Enabled = False
Timer3Enabled = False
Label5Caption = "用法:1 开始录制时按下 A 键停止录制;" & vbCrLf & _
" 2 本软件还可以按下 S 锁定鼠标和键盘,不可移动;" & vbCrLf & _
" 3 本软件还可以按下 D 锁定鼠标和键盘,可移动;" & vbCrLf & _
" 4 每个控制都有一个快捷键,就是每个按钮后括号内。" & vbCrLf & _
vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
" " & AppTitle + "( 版本 " & AppMajor & "" & AppMinor & "" & AppRevision & " )" '当前版本号是
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 Text2Text > 0 Then Timer2Interval = Text2Text
End Sub
'读保文件
Private Sub Command3_Click() 'List1 保存 txt
Dim fn As Integer, i As Integer
fn = FreeFile
Open Text1Text For Output As #1
For i = 0 To List1ListCount - 1
Print #1, List1List(i)
Next
Close #1
MsgBox "成功保存到: " & Text1Text
End Sub
Private Sub Command4_Click() 'List1 读取 txt
List1Clear '清空
Open Text1Text For Input As #1
Do While Not EOF(1)
Line Input #1, Temp
List1AddItem Temp
Loop
Close #1
End Sub
'清空List1
Private Sub Command5_Click()
List1Clear
End Sub
'回放录制
Private Sub Command2_Click()
ShFu
If List1ListCount > 0 Then
List1ListIndex = 1
Form1Caption = "记录鼠标 - 正在回放"
Timer2Enabled = True
End If
End Sub
Private Sub Timer2_Timer()
Dim x
List1ListIndex = List1ListIndex - 0 + 1
x = Split(List1Text, "<>")
SetCursorPos x(0), x(1) '你所需要点的位置
If x(2) = "左" Then ZuoDanJi
If x(2) = "中" Then ZongDanJi
If x(2) = "右" Then YouDanJi
If List1ListIndex >= List1ListCount - 1 Then Form1Caption = "记录鼠标": CC = "停锁记录鼠标": YhFu: Timer2Enabled = 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
Form1Caption = "记录鼠标 - 正在录制(按下A键停止)"
End Sub
'录制
Private Sub Tttex_Change()
If Form1Caption = "记录鼠标 - 正在录制(按下A键停止)" Then List1AddItem TttexText
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
TttexText = P1x & "<>" & P1y & "<>" & MousG
MousG = "0"
'快捷键
If MyHotKey(vbKeyA) Then Form1Caption = "记录鼠标": 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 Form1Caption = "记录鼠标 - 锁定鼠标和键盘不可移动 " & SSSDDD & "秒后解锁"
If CC = "可移动" Then Form1Caption = "记录鼠标 - 锁定鼠标和键盘可移动 " & SSSDDD & "秒后解锁"
If SSSDDD < 1 Then
BlockInput (0)
Form1Caption = "记录鼠标"
CC = "停锁记录鼠标"
Timer3Enabled = False
YhFu
End If '恢复
End Sub
Private Sub SSS()
Form1Caption = "记录鼠标 - 锁定鼠标和键盘,不可移动"
SSSDDD = InputBox("提示", "请问你想锁定多少秒?", "10")
CC = "不可移动"
Timer3Enabled = True
BlockInput (5) '锁定,不可移动
End Sub
Private Sub DDD()
Form1Caption = "记录鼠标 - 锁定鼠标和键盘,可移动"
SSSDDD = InputBox("提示", "请问你想锁定多少秒?", "10")
CC = "可移动"
Timer3Enabled = True
Call Sleep(SSSDDD) '锁定,可移动
End Sub
' *** 作时是否可以看到本软件
Private Sub ShFu() '
If Check1Value = 0 Then Form1Hide '隐藏
End Sub
Private Sub YhFu() '
If CC = "停锁记录鼠标" Then
Form1Show '显示
CC = "鼠标记录"
End If
End Sub
'删除List1中的一行
Private Sub List1_DblClick() '
List1RemoveItem List1ListIndex
End Sub
'退出
Private Sub Command6_Click()
End
End Sub
腾讯的程序会对消息钩子进行HOOK,如果你先HOOK再启动程序当然会有冲突,而你先运行程序再HOOK的话有是在腾讯的监视下 *** 作而不会成功,可以试下在内核中对native api进行HOOK
您在功能上虽然说的不是外挂但是他确实是从外挂的入口而入
要钩子防止被游戏屏蔽,方式其实也简单,用另外一个程序盖上例如所谓全局钩子你不要在游戏加载时加载可以尝试完全修改键盘按键逻辑
再例如不要直接尝试与游戏对接
游戏的反外挂其实也简单反你的钩子更简单
反你钩子只需要定义出键盘本身的偏移量对比即可
亲别忘了游戏自己本身就能设置改键
那么你的钩子与游戏的改键是否冲突你检查过
要考虑的不仅仅是改一个键而是整套逻辑
开机启动不要写注册表,直接将程序放在“开始”--“所有程序”--“启动”目录下面即可。
CSIDL_STARTUP 这个代表启动文件夹
具体获取如下:
useShlObj;
function GetStartupPath: String;
var
PidL: PItemIDList;
FavPath: Array[0MAX_PATH] of Char;
begin
SHGetSpecialFolderLocation(ApplicationHandle, CSIDL_STARTUP, PidL);
SHGetPathFromIDList(PidL, FavPath);
Result:= String(FavPath);
end;
以上就是关于VS 2010 C++ ,写了一个全局的键盘钩子keyhook.dll,然后通过控制台程序调用;在keyhook.dll中导出......全部的内容,包括:VS 2010 C++ ,写了一个全局的键盘钩子keyhook.dll,然后通过控制台程序调用;在keyhook.dll中导出......、用vb做全局鼠标键盘钩子。。。求助。。、WIN32 汇编全局键盘钩子等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)