设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1743|回复: 4
打印 上一主题 下一主题

[已经解决] 按下鼠标左键应该怎么写代码?

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
207 小时
注册时间
2014-8-16
帖子
132
跳转到指定楼层
1
发表于 2015-5-29 14:50:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
按下鼠标左键应该怎么希望代码?if Input.trigger?(Input::C)我想把它修改成鼠标的左键,应该怎么写,都有几种写法.,谢谢!

评分

参与人数 1星屑 +35 收起 理由
RyanBern + 35 手动认可奖励

查看全部评分

Lv3.寻梦者

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
帖子
1516
2
发表于 2015-5-29 17:26:35 | 只看该作者
主要是调用win32。下面这个大概是某位大神的脚本,不记得谁了。

  1. GetAsyncKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
  2. #1、Kboard.press?(key) 同 Input.press?(key)
  3. #2、Kboard.repeat?(key) 同 Input.repeat?(key)
  4. #3、Kboard.trigger?(key) 同 Input.trigger?(key)
  5. module Kboard
  6.         #==========================================================================
  7.         # 以下是全键盘按键列表
  8.         #--------------------------------------------------------------------------
  9.         M_L = 0x01        # left mouse button
  10.         M_R = 0x02        # right mouse button

  11.         @R_Key_Hash = {}
  12.         @R_Key_Repeat = {}
  13.        
  14.         def self.press?(rkey)
  15.                 return GetAsyncKeyState.call(rkey) != 0
  16.         end
  17.        
  18.         def self.repeat?(rkey)
  19.                 result = GetAsyncKeyState.call(rkey)
  20.                 if result != 0
  21.                         if @R_Key_Repeat[rkey].nil?
  22.                                 @R_Key_Repeat[rkey] = 0
  23.                                 return true
  24.                         end
  25.                         @R_Key_Repeat[rkey] += 1
  26.                 else
  27.                         @R_Key_Repeat[rkey] = nil
  28.                         @R_Key_Hash[rkey] = 0
  29.                 end
  30.                 if !@R_Key_Repeat[rkey].nil? and @R_Key_Repeat[rkey] > 4 # 4乃准确数字
  31.                         @R_Key_Repeat[rkey] = 0
  32.                         return true
  33.                 else
  34.                         return false
  35.                 end
  36.         end
  37.        
  38.         def self.trigger?(rkey)
  39.                 result = GetAsyncKeyState.call(rkey)
  40.                 if @R_Key_Hash[rkey] == 1 and result != 0
  41.                         return false
  42.                 end
  43.                 if result != 0
  44.                         @R_Key_Hash[rkey] = 1
  45.                         return true
  46.                 else
  47.                         @R_Key_Hash[rkey] = 0
  48.                         return false
  49.                 end
  50.         end
  51. end

复制代码
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
76
在线时间
1379 小时
注册时间
2012-7-5
帖子
1698

开拓者

3
发表于 2015-5-30 19:00:40 | 只看该作者
本帖最后由 kuerlulu 于 2015-5-30 19:19 编辑

自己写的鼠标脚本:
  1. def _api code; Win32API.new *code.split("|"); end

  2. #==============================================================================
  3. # ■ Mouse
  4. #------------------------------------------------------------------------------
  5. #   处理鼠标输入信息的模块。
  6. #==============================================================================
  7. module Mouse
  8.   #--------------------------------------------------------------------------
  9.   # ● 监视器
  10.   #--------------------------------------------------------------------------
  11.   Monitor = {
  12.     :pos         => [0, 0],
  13.     :last_pos    => [0, 0],
  14.     :save_pos    => [0, 0],
  15.     :button      => 0,
  16.     :last_button => 0,
  17.     :timer       => 0,
  18.   }
  19.   Dragage = {}
  20.   #--------------------------------------------------------------------------
  21.   # ● API
  22.   #--------------------------------------------------------------------------
  23.   GetCursorPos     = _api "user32|GetCursorPos|p|i"
  24.   ScreenToClient   = _api "user32|ScreenToClient|pp|i"
  25.   GetActiveWindow  = _api "user32|GetActiveWindow||i"
  26.   GetAsyncKeyState = _api "user32|GetAsyncKeyState|i|i"
  27.   ShowCursor       = _api "user32|ShowCursor|i|i"
  28. class << self
  29.   def update
  30.     # ● 更新监视器
  31.     Monitor[:last_pos] = Monitor[:pos]
  32.     Monitor[:pos] = _pos
  33.     Monitor[:last_button] = Monitor[:button]
  34.     Monitor[:button] = (_press? 0x01) ? 1 : (_press? 0x02) ? 2 : (
  35.       _press?(0x04) ? 3 : 0 )
  36.     Monitor[:last_button] == Monitor[:button] ? Monitor[:timer] += 1 : (
  37.       Monitor[:timer] = 0 )
  38.     # ● 更新拖动
  39.     Monitor[:save_pos] = Monitor[:pos] if down_left?
  40.     Dragage.clear if Monitor[:button] == 0 && !Dragage.empty?
  41.   end
  42.   #--------------------------------------------------------------------------
  43.   def _press? button
  44.     GetAsyncKeyState.call(button).abs & 0x8000 == 0x8000
  45.   end
  46.   def _pos
  47.     GetCursorPos.call buffer = "\0"*8
  48.     ScreenToClient.call GetActiveWindow.call, buffer
  49.     buffer.unpack "ll"
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● 快速找到正确的姿势
  53.   #--------------------------------------------------------------------------
  54.   def pos; Monitor[:pos]; end
  55.   def button; Monitor[:button]; end
  56.   def moving?; Monitor[:timer] == 0; end
  57.   def down_left?; Monitor[:button] == 1 && Monitor[:last_button] == 0; end
  58.   def down_right?; Monitor[:button] == 2 && Monitor[:last_button] == 0; end
  59.   def hold_left?; Monitor[:button] == 1 && Monitor[:last_button] == 1; end
  60.   def hold_right?; Monitor[:button] == 2 && Monitor[:last_button] == 2; end
  61.   def up_left?; Monitor[:button] == 0 && Monitor[:last_button] == 1; end
  62.   def up_right?; Monitor[:button] == 0 && Monitor[:last_button] == 2; end
  63.   def hold?; hold_left? || hold_right?; end
  64.   alias click? down_left?
  65.   alias right_click? down_right?
  66.   def add(obj); Dragage[obj] = [obj.x, obj.y, obj.width, obj.height]; end
  67.   def hide; ShowCursor.call(0); end
  68.   def show; ShowCursor.call(1); end
  69.   #--------------------------------------------------------------------------
  70.   def area?(*args)
  71.     case args.size
  72.     when 1 then rect?(args[0].x, args[0].y, args[0].width, args[0].height)
  73.     when 4 then rect?(*args)
  74.     end
  75.   end
  76.   def rect?(x, y, width, height)
  77.     Monitor[:pos][0].between?(x, x + width) &&
  78.     Monitor[:pos][1].between?(y, y + height)
  79.   end
  80.   def [](arg)
  81.     return Monitor[arg] if arg.is_a? Symbol
  82.     Dragage[arg]
  83.   end
  84.   def has?(obj)
  85.     Dragage.keys.include?(obj)
  86.   end
  87.   private :_press?, :_pos
  88. end
  89. end

  90. class << Input
  91.   alias hy_update update
  92.   def update
  93.     hy_update
  94.     Mouse.update
  95.   end
  96. end
复制代码
调用姿势: Mouse.click?

评分

参与人数 1星屑 +200 收起 理由
RyanBern + 200 认可答案

查看全部评分


  -fk: -azogi:
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
207 小时
注册时间
2014-8-16
帖子
132
4
 楼主| 发表于 2015-5-30 20:48:42 | 只看该作者
kuerlulu 发表于 2015-5-30 19:00
自己写的鼠标脚本:调用姿势: Mouse.click?


如果调用鼠标左键,该怎么写?谢谢!

点评

Win32API.new("user32", "keybd_event", "iiii", 'l').call(0x01)  发表于 2015-5-30 21:04
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1743
在线时间
485 小时
注册时间
2006-1-7
帖子
1073
5
发表于 2015-5-30 21:18:39 | 只看该作者
给你一个全键盘脚本,这样键盘上所有按钮你都可以调用了。
我个人还添加了注解,因为原来作者的注解实在蛋疼

我觉得注解内容你应该看得懂
按一下鼠标左键
就是  if Kboard.keyboard($Rmouse_BUTTON_L)


全键盘脚本
初从文,三年不中;后习武,校场发一矢,中鼓吏,逐之出;遂学医,有所成。自撰一良方,服之,卒。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-22 23:32

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表