被刷百万点赞背后的故事,是颜值的支撑还是技术的提升?

Posted houxinlin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了被刷百万点赞背后的故事,是颜值的支撑还是技术的提升?相关的知识,希望对你有一定的参考价值。

小伙伴们是否已经直播上课?是否为你们可爱的老师点赞,又是否破了百万呢?

至少我们是这样 [此处手动狗头]。
技术图片
毫无疑问这不可能纯手破百万的,这仅仅三十多人而已。无非就是些鼠标连点器在不停的模拟点击,本文就介绍下鼠标连点器的实现原理。

一、mouse_event

实现连点器的关键,就是mouse_event函数,但是这个函数和其他函数有一个不同点,那就是命名格式,一般Win API很少出现这种风格,不知道是什么原因,就像Java中的Hashtable,但是不影响我们使用。

mouse_event在MSDN中说明已被SendInput取代,但是SendInput不太了解,还是介绍mouse_event吧。
技术图片
dwFlags:这个参数也就是指明那个键被按下,取值如下。

MOUSEEVENTF_ABSOLUTE dX和dY参数含有规范化的绝对坐标
MOUSEEVENTF_LEFTDOWN 左按钮按下
MOUSEEVENTF_LEFTUP 左按钮抬起
MOUSEEVENTF_MIDDLEDOWN 中间按钮按下
MOUSEEVENTF_MIDDLEUP 中间按钮抬起
MOUSEEVENTF_MOVE 移动
MOUSEEVENTF_RIGHTDOWN 右按钮按下
MOUSEEVENTF_RIGHTUP 右按钮抬起
MOUSEEVENTF_WHEEL 滑轮

....
dx:指定鼠标沿x轴的绝对位置或者从上次鼠标事件产生以来移动的数量,依赖于MOUSEEVENTF_ABSOLUTE的设置。

dy:指定鼠标沿y轴的绝对位置或者从上次鼠标事件产生以来移动的数量,依赖于MOUSEEVENTF_ABSOLUTE的设置。

dwData:如果dwFlags为MOUSEEVENTF_WHEEL,则dwData指定鼠标轮移动的数量。正值表明鼠标轮向前转动,负值表明鼠标轮向后转动,即朝向用户。

dwExtralnfo:指定与鼠标事件相关的附加32位值。

所以最终完成一次左键按下抬起操作,也就是一行。

mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0.

光知道怎么模拟其实还是不够的啊,因为还需要有热键开始暂停。

二、RegisterHotKey

见名知意,这是用来注册热键的,像我们QQ的截图快捷键Ctrl+Alt+A或者是微信的截图快捷键Ctlr+A。
技术图片
hWnd:窗口的句柄。
id:热键标识符。
fsModifiers:取以下值,也就是可以指明热键是否带有Ctrl、Alt等键。

MOD_ALT Alt键
MOD_SHIFT Shift键键
MOD_WIN Windows键
MOD_NOREPEAT 更改热键行为,以便键盘自动重复不会产生多个热键通知
MOD_CONTROL Ctrl键

vk:指明虚拟键码,比如热键是A,则取65。

这个函数具体处理是在窗口函数中,热键被触发时,窗口函数会接收的WM_HOTKEY消息。wParam就是上面传入的热键标识符,lParam的低位表示fsModifiers的值,高位表示vk的值。

像这些小程序开发,没有比VB更合适的了,但是VB又封装了窗口函数,所以我们又得需要GetWindowLong、SetWindowLong来修改默认的窗口函数。

WndFunchw = GetWindowLong(Me.hwnd, GWL_WNDPROC)
Call SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf Proc)

为了防止开始模拟点击后,鼠标被误移动,从而点到其他东西,所以还需要在开始后,不让鼠标移动到其他位置。最简单可以使用GetCursorPos、SetCursorPos。

GetCursorPos在开始时获取鼠标位置并保存下来,SetCursorPos是设置鼠标位置。

三、完整代码

模块中

Public Declare Function RegisterHotKey Lib "user32.dll" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32.dll" (ByVal hwnd As Long, ByVal id As Long) As Long
Public Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Type POINTAPI
X As Long
Y As Long
End Type
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Public Declare Function SetCursorPos Lib "user32.dll" (ByVal X As Long, ByVal Y As Long) As Long

Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC As Long = -4

Public Const WM_HOTKEY As Long = &H312


Public 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)

Public Const MOUSEEVENTF_MOVE = &H1
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20
Public Const MOUSEEVENTF_MIDDLEUP = &H40
Public Const MOUSEEVENTF_ABSOLUTE = &H8000
Public Const HOTLEFT As Integer = 1
Public Const HOTUP As Integer = 2
Public Const HOTRIGHT As Integer = 3
Public Const HOTDOWN As Integer = 4
Public Const HOT_KEY_ID As Integer = 5
Public Const MOD_ALT As Long = &H1
Public Const MOD_CONTROL As Long = &H2

Public hWndFunc As Long
Public isPlay As Boolean
Public mCruuentPoint As POINTAPI

Public Function Proc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Select Case Msg
Case WM_HOTKEY
    If wParam = HOT_KEY_ID Then
        If isPlay = False Then
            Call GetCursorPos(mCruuentPoint)
        End If
        isPlay = Not isPlay
        Form1.Timer1.Enabled = isPlay
    End If

End Select

Proc = CallWindowProc(hWndFunc, hwnd, Msg, wParam, lParam)
End Function

窗体

Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1

hWndFunc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
Call SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf Proc)
Dim r As Long
r = RegisterHotKey(Me.hwnd, HOT_KEY_ID, MOD_CONTROL, Asc("B"))
 If r = 0 Then
    MsgBox "热键注册失败,请关闭使用方向键为ALT+S的程序"
   rk = False
 End If
Label2.Caption = "将鼠标移动到点赞按钮处,安Ctrl+B键 开始暂停"

End Sub

Private Sub Label2_Click()
	Static count As Long
	count = count + 1
	Me.Caption = count
End Sub

Private Sub Timer1_Timer()
	SetCursorPos mCruuentPoint.X, mCruuentPoint.Y
	Label1.Caption = "开始疯狂输出"
	mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub

以上是关于被刷百万点赞背后的故事,是颜值的支撑还是技术的提升?的主要内容,如果未能解决你的问题,请参考以下文章

怒刷3000条短视频后,我终于发现网红300万点赞的套路

算法也是颜值控,Twitter AI更青睐肤白貌美图

算法也是颜值控,Twitter AI更青睐肤白貌美图

算法也是颜值控,Twitter AI更青睐肤白貌美图

轻薄本标杆 颜值天花板!全新荣耀MagicBook X 14 笔记本评测

书单|可以提高男生颜值的7本书(入门篇)