level 1
金鱼师傅
楼主
分享链接:
百度网盘
和66RPG那个鼠标输入的原理不同,通过拦截窗口消息获取,所以可以获取鼠标滚轮(通过)scroll方法,懂windows消息的通过分析message和wparam也能判断窗口是否失去焦点。
必须配合talib.dll使用
没有钩子,不担心警报。
dll静态链接,不需要用户安装MSVCR*.dll
ruby部分代码如下,每帧调用一次call
module Ta
class KeyState
attr_reader:cx, :cy, :message, :wparam, :lparam, :time
def press?(i)
@now[i]
end
def click?(i)
@now[i] && !@last[i]
end
def release?(i)
@last[i] && !@now[i]
end
def scroll
@message == 522 ?(@wparam & 0x80000000 == 0 ? -1 : 1) : 0
end
def bound_cursor(x, y)
return [[0, x].max, Graphics.width].min, [[0, y].max, Graphics.height].min
end
def move_cursor(x, y)
@cx, @cy = bound_cursor(x, y)
pos = [@cx, @cy].pack('ll')
if @clientToScreen.call(@hwnd,pos) != 0
sx, sy = pos.unpack('ll')
@setCursorPos.call(sx, sy)
end
end
def show_cursor=(v)
@showCursor.call(v ? 1 : 0)
end
def initialize
@showCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
@setCursorPos = Win32API.new("user32", "SetCursorPos", 'ii', 'i')
@clientToScreen = Win32API.new("user32", "ClientToScreen", 'ip', 'i')
@getActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
@hwnd = @getActiveWindow.call
@getKeyboardState = Win32API.new("user32", "GetKeyboardState", 'p', 'i')
@last_msg = Win32API.new("talib", "last_msg", 'ip', 'i')
@last_msg.call(@hwnd,nil)
@wheel = 0
@now, @last = Array.new(163, false), Array.new(163, false)
@message, @wparam, @lparam, @time, @cx, @cy = 0,0,0,0,0,0,0
end
def call
msg = Array.new(8,0).pack 'l*'
@last_msg.call(@hwnd,msg)
_, @message, @wparam, @lparam, @time, @cx, @cy = msg.unpack 'l*'
@cx, @cy = bound_cursor(@cx, @cy)
buf = Array.new(256,0).pack('c*')
if @getKeyboardState.call(buf) != 0
buf = buf.unpack 'c*'
temp = @last
@last = @now
@now = temp.fill{|i| buf[i] & 0x80 != 0}
end
end
end
end
2015年01月05日 01点01分
1
百度网盘
和66RPG那个鼠标输入的原理不同,通过拦截窗口消息获取,所以可以获取鼠标滚轮(通过)scroll方法,懂windows消息的通过分析message和wparam也能判断窗口是否失去焦点。
必须配合talib.dll使用
没有钩子,不担心警报。
dll静态链接,不需要用户安装MSVCR*.dll
ruby部分代码如下,每帧调用一次call
module Ta
class KeyState
attr_reader:cx, :cy, :message, :wparam, :lparam, :time
def press?(i)
@now[i]
end
def click?(i)
@now[i] && !@last[i]
end
def release?(i)
@last[i] && !@now[i]
end
def scroll
@message == 522 ?(@wparam & 0x80000000 == 0 ? -1 : 1) : 0
end
def bound_cursor(x, y)
return [[0, x].max, Graphics.width].min, [[0, y].max, Graphics.height].min
end
def move_cursor(x, y)
@cx, @cy = bound_cursor(x, y)
pos = [@cx, @cy].pack('ll')
if @clientToScreen.call(@hwnd,pos) != 0
sx, sy = pos.unpack('ll')
@setCursorPos.call(sx, sy)
end
end
def show_cursor=(v)
@showCursor.call(v ? 1 : 0)
end
def initialize
@showCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
@setCursorPos = Win32API.new("user32", "SetCursorPos", 'ii', 'i')
@clientToScreen = Win32API.new("user32", "ClientToScreen", 'ip', 'i')
@getActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
@hwnd = @getActiveWindow.call
@getKeyboardState = Win32API.new("user32", "GetKeyboardState", 'p', 'i')
@last_msg = Win32API.new("talib", "last_msg", 'ip', 'i')
@last_msg.call(@hwnd,nil)
@wheel = 0
@now, @last = Array.new(163, false), Array.new(163, false)
@message, @wparam, @lparam, @time, @cx, @cy = 0,0,0,0,0,0,0
end
def call
msg = Array.new(8,0).pack 'l*'
@last_msg.call(@hwnd,msg)
_, @message, @wparam, @lparam, @time, @cx, @cy = msg.unpack 'l*'
@cx, @cy = bound_cursor(@cx, @cy)
buf = Array.new(256,0).pack('c*')
if @getKeyboardState.call(buf) != 0
buf = buf.unpack 'c*'
temp = @last
@last = @now
@now = temp.fill{|i| buf[i] & 0x80 != 0}
end
end
end
end