Project1
标题:
按下鼠标左键应该怎么写代码?
[打印本页]
作者:
a107480098
时间:
2015-5-29 14:50
标题:
按下鼠标左键应该怎么写代码?
按下鼠标左键应该怎么希望代码?if Input.trigger?(Input::C)我想把它修改成鼠标的左键,应该怎么写,都有几种写法.,谢谢!
作者:
汪汪
时间:
2015-5-29 17:26
主要是调用win32。下面这个大概是某位大神的脚本,不记得谁了。
GetAsyncKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
#1、Kboard.press?(key) 同 Input.press?(key)
#2、Kboard.repeat?(key) 同 Input.repeat?(key)
#3、Kboard.trigger?(key) 同 Input.trigger?(key)
module Kboard
#==========================================================================
# 以下是全键盘按键列表
#--------------------------------------------------------------------------
M_L = 0x01 # left mouse button
M_R = 0x02 # right mouse button
@R_Key_Hash = {}
@R_Key_Repeat = {}
def self.press?(rkey)
return GetAsyncKeyState.call(rkey) != 0
end
def self.repeat?(rkey)
result = GetAsyncKeyState.call(rkey)
if result != 0
if @R_Key_Repeat[rkey].nil?
@R_Key_Repeat[rkey] = 0
return true
end
@R_Key_Repeat[rkey] += 1
else
@R_Key_Repeat[rkey] = nil
@R_Key_Hash[rkey] = 0
end
if !@R_Key_Repeat[rkey].nil? and @R_Key_Repeat[rkey] > 4 # 4乃准确数字
@R_Key_Repeat[rkey] = 0
return true
else
return false
end
end
def self.trigger?(rkey)
result = GetAsyncKeyState.call(rkey)
if @R_Key_Hash[rkey] == 1 and result != 0
return false
end
if result != 0
@R_Key_Hash[rkey] = 1
return true
else
@R_Key_Hash[rkey] = 0
return false
end
end
end
复制代码
作者:
kuerlulu
时间:
2015-5-30 19:00
本帖最后由 kuerlulu 于 2015-5-30 19:19 编辑
自己写的鼠标脚本
:
def _api code; Win32API.new *code.split("|"); end
#==============================================================================
# ■ Mouse
#------------------------------------------------------------------------------
# 处理鼠标输入信息的模块。
#==============================================================================
module Mouse
#--------------------------------------------------------------------------
# ● 监视器
#--------------------------------------------------------------------------
Monitor = {
:pos => [0, 0],
:last_pos => [0, 0],
:save_pos => [0, 0],
:button => 0,
:last_button => 0,
:timer => 0,
}
Dragage = {}
#--------------------------------------------------------------------------
# ● API
#--------------------------------------------------------------------------
GetCursorPos = _api "user32|GetCursorPos|p|i"
ScreenToClient = _api "user32|ScreenToClient|pp|i"
GetActiveWindow = _api "user32|GetActiveWindow||i"
GetAsyncKeyState = _api "user32|GetAsyncKeyState|i|i"
ShowCursor = _api "user32|ShowCursor|i|i"
class << self
def update
# ● 更新监视器
Monitor[:last_pos] = Monitor[:pos]
Monitor[:pos] = _pos
Monitor[:last_button] = Monitor[:button]
Monitor[:button] = (_press? 0x01) ? 1 : (_press? 0x02) ? 2 : (
_press?(0x04) ? 3 : 0 )
Monitor[:last_button] == Monitor[:button] ? Monitor[:timer] += 1 : (
Monitor[:timer] = 0 )
# ● 更新拖动
Monitor[:save_pos] = Monitor[:pos] if down_left?
Dragage.clear if Monitor[:button] == 0 && !Dragage.empty?
end
#--------------------------------------------------------------------------
def _press? button
GetAsyncKeyState.call(button).abs & 0x8000 == 0x8000
end
def _pos
GetCursorPos.call buffer = "\0"*8
ScreenToClient.call GetActiveWindow.call, buffer
buffer.unpack "ll"
end
#--------------------------------------------------------------------------
# ● 快速找到正确的姿势
#--------------------------------------------------------------------------
def pos; Monitor[:pos]; end
def button; Monitor[:button]; end
def moving?; Monitor[:timer] == 0; end
def down_left?; Monitor[:button] == 1 && Monitor[:last_button] == 0; end
def down_right?; Monitor[:button] == 2 && Monitor[:last_button] == 0; end
def hold_left?; Monitor[:button] == 1 && Monitor[:last_button] == 1; end
def hold_right?; Monitor[:button] == 2 && Monitor[:last_button] == 2; end
def up_left?; Monitor[:button] == 0 && Monitor[:last_button] == 1; end
def up_right?; Monitor[:button] == 0 && Monitor[:last_button] == 2; end
def hold?; hold_left? || hold_right?; end
alias click? down_left?
alias right_click? down_right?
def add(obj); Dragage[obj] = [obj.x, obj.y, obj.width, obj.height]; end
def hide; ShowCursor.call(0); end
def show; ShowCursor.call(1); end
#--------------------------------------------------------------------------
def area?(*args)
case args.size
when 1 then rect?(args[0].x, args[0].y, args[0].width, args[0].height)
when 4 then rect?(*args)
end
end
def rect?(x, y, width, height)
Monitor[:pos][0].between?(x, x + width) &&
Monitor[:pos][1].between?(y, y + height)
end
def [](arg)
return Monitor[arg] if arg.is_a? Symbol
Dragage[arg]
end
def has?(obj)
Dragage.keys.include?(obj)
end
private :_press?, :_pos
end
end
class << Input
alias hy_update update
def update
hy_update
Mouse.update
end
end
复制代码
调用姿势: Mouse.click?
作者:
a107480098
时间:
2015-5-30 20:48
kuerlulu 发表于 2015-5-30 19:00
自己写的鼠标脚本:调用姿势: Mouse.click?
如果调用鼠标左键,该怎么写?谢谢!
作者:
白鬼
时间:
2015-5-30 21:18
给你一个全键盘脚本,这样键盘上所有按钮你都可以调用了。
我个人还添加了注解,因为原来作者的注解实在蛋疼
我觉得注解内容你应该看得懂
按一下鼠标左键
就是 if Kboard.keyboard($Rmouse_BUTTON_L)
全键盘脚本
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1