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

Project1

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

[已经解决] 如何判断按下鼠标左键

[复制链接]

Lv1.梦旅人

梦石
0
星屑
60
在线时间
305 小时
注册时间
2009-8-21
帖子
119
跳转到指定楼层
1
发表于 2010-12-9 11:51:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 wxs29 于 2010-12-10 12:11 编辑
  1. #==============================================================================
  2. # ** 鼠标输出模块 (修复)
  3. #------------------------------------------------------------------------------
  4. #   by DerVVulfman
  5. #   版本 1.2
  6. #   08-18-2007
  7. #------------------------------------------------------------------------------
  8. #   建立在鼠标输出模块...
  9. #
  10. #   by Near Fantastica
  11. #------------------------------------------------------------------------------
  12. #   Set_Pos feature by
  13. #   Freakboy
  14. #------------------------------------------------------------------------------
  15. #
  16. #   CALLS:
  17. #
  18. #   Mouse.click?
  19. #   判断鼠标是否真的按下(Ture/False).
  20. #   这个值控制您按下的是左/右键,还是中键

  21. #
  22. #   Mouse.press?
  23. #   判断鼠标是否真的按下/保持按下状态
  24. #   这个值控制您按下的是左/右键,还是中键
  25. #   Mouse.pixels
  26. #   Mouse.pixels
  27. #   这个值返回鼠标所在的坐标(640*480大小),如果鼠标超出游戏画面,这个值为空
  28. #
  29. #   Mouse.tiles
  30. #   This returns  the mouse's screen  coordinates  in map tiles.   Based on the
  31. #   system's 20x15 tile size,  this returns it in index values  (a 0-19 width &
  32. #   a 0-14 height).  This functions the same manner as Mouse.pixels.
  33. #
  34. #   Mouse.set_pos
  35. #   This allows you  to forcefully position the mouse at an x/y position within
  36. #   the game screen by pixel coordinates.  Given the game's normal screen width
  37. #   of 640x480, adding:  Mouse.set_pos(320,240)  should position the mouse dead
  38. #   center of the gaming window.
  39. #
  40. #   Mouse.update
  41. #   Add this routine  into your update routines  to update  the mouse position.
  42. #   It must be called otherwise you won't get valid mouse coordinates.
  43. #
  44. #==============================================================================

  45. module Mouse
  46.   @mouse_menu = 0
  47.   #--------------------------------------------------------------------------
  48.   # * 鼠标点击
  49.   #     button      : button
  50.   #--------------------------------------------------------------------------
  51.   def Mouse.click?(button)
  52.     return true if @keys.include?(2) and button == 2
  53.     return true if @keys.include?(button) and $click_abled
  54.     return false
  55.   end  
  56.   #--------------------------------------------------------------------------
  57.   # * 鼠标击键
  58.   #     button      : button
  59.   #--------------------------------------------------------------------------
  60.   def Mouse.press?(button)
  61.     return true if @press.include?(button)
  62.     return false
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # * 鼠标按下
  66.   #     button      : button
  67.   #--------------------------------------------------------------------------
  68.   def Mouse.area?(x, y, width=32, height=32)
  69.     return false if @pos == nil
  70.     return true if @pos[0] >= x and @pos[0] <= (x+width) and @pos[1] >= y and @pos[1] <= (y+height)
  71.     return false
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * 坐标
  75.   #--------------------------------------------------------------------------
  76.   def Mouse.pixels
  77.     return @pos == nil ? [0, 0] : @pos
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * 鼠标初始坐标
  81.   #--------------------------------------------------------------------------
  82.   def Mouse.tiles
  83.     return nil if @pos == nil
  84.     x = @pos[0] / 32
  85.     y = @pos[1] / 32
  86.     return [x, y]
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # * 设置鼠标初始坐标
  90.   #--------------------------------------------------------------------------
  91.   def Mouse.set_pos(x_pos=0, y_pos=0)
  92.     width, height = Mouse.client_size
  93.     if (x_pos.between?(0, width) && y_pos.between?(0, height))
  94.       x = Mouse.client_pos[0] + x_pos; y = Mouse.client_pos[1] + y_pos
  95.       Win32API.new('user32', 'SetCursorPos', 'NN', 'N').call(x, y)
  96.     end
  97.   end
  98.   #--------------------------------------------------------------------------
  99.   # * Mouse Update
  100.   #--------------------------------------------------------------------------
  101.   def Mouse.update
  102.     @pos            = Mouse.pos
  103.     @keys, @press   = [], []
  104.     @keys.push(1)   if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(1) & 0X01 == 1
  105.     @keys.push(2)   if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(2) & 0X01 == 1
  106.     @keys.push(3)   if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(4) & 0X01 == 1
  107.     @press.push(1)  if Win32API.new("user32","GetKeyState",['i'],'i').call(1) & 0X01 == 1
  108.     @press.push(2)  if Win32API.new("user32","GetKeyState",['i'],'i').call(2) & 0X01 == 1
  109.     @press.push(3)  if Win32API.new("user32","GetKeyState",['i'],'i').call(4) & 0X01 == 1
  110.   end  
  111.   #--------------------------------------------------------------------------
  112.   # * Automatic functions below
  113.   #--------------------------------------------------------------------------
  114.   #
  115.   #--------------------------------------------------------------------------
  116.   # * Obtain Mouse position in screen
  117.   #--------------------------------------------------------------------------
  118.   def Mouse.global_pos
  119.     pos = [0, 0].pack('ll')
  120.     if Win32API.new('user32', 'GetCursorPos', 'p', 'i').call(pos) != 0
  121.       return pos.unpack('ll')
  122.     else
  123.       return nil
  124.     end
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # * 返回鼠标坐标
  128.   #--------------------------------------------------------------------------
  129.   def Mouse.pos
  130.     x, y = Mouse.screen_to_client(*Mouse.global_pos)
  131.     width, height = Mouse.client_size
  132.     begin
  133.       if (x >= 0 and y >= 0 and x < width and y < height)
  134.         return x, y
  135.       else
  136.         return nil
  137.       end
  138.     rescue
  139.       return nil
  140.     end
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   #  * Pass Screen to Game System
  144.   #--------------------------------------------------------------------------
  145.   def Mouse.screen_to_client(x, y)
  146.     return nil unless x and y
  147.     pos = [x, y].pack('ll')
  148.     if Win32API.new('user32', 'ScreenToClient', %w(l p), 'i').call(Mouse.hwnd, pos) != 0
  149.       return pos.unpack('ll')
  150.     else
  151.       return nil
  152.     end
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # * 得到游戏屏幕高度
  156.   #--------------------------------------------------------------------------
  157.   def Mouse.hwnd
  158.     game_name = "\0" * 256
  159.     Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l').call('Game','Title','',game_name,255,".\\Game.ini")
  160.     game_name.delete!("\0")
  161.     return Win32API.new('user32', 'FindWindowA', %w(p p), 'l').call('RGSS Player',game_name)
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # * 得到游戏屏幕宽度
  165.   #--------------------------------------------------------------------------
  166.   def Mouse.client_size
  167.     rect = [0, 0, 0, 0].pack('l4')
  168.     Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(Mouse.hwnd, rect)
  169.     right, bottom = rect.unpack('l4')[2..3]
  170.     return right, bottom
  171.   end
  172.   #--------------------------------------------------------------------------
  173.   # * 得到窗口坐标
  174.   #--------------------------------------------------------------------------
  175.   def Mouse.client_pos
  176.     rect = [0, 0, 0, 0].pack('l4')
  177.     Win32API.new('user32', 'GetWindowRect', %w(l p), 'i').call(Mouse.hwnd, rect)
  178.     left, upper = rect.unpack('l4')[0..1]
  179.     return left+4, upper+30
  180.   end
  181. end
复制代码
如何判断按下鼠标左键?

Lv2.观梦者

Adam

梦石
0
星屑
688
在线时间
841 小时
注册时间
2010-8-24
帖子
2595
2
发表于 2010-12-9 12:43:22 | 只看该作者
鼠标点一下就是咯.....
嘛,摸了。
回复 支持 反对

使用道具 举报

Lv5.捕梦者 (管理员)

老黄鸡

梦石
0
星屑
39679
在线时间
7486 小时
注册时间
2009-7-6
帖子
13483

开拓者贵宾

3
发表于 2010-12-9 13:21:09 | 只看该作者
定义写的很清楚了。用Mouse.press?或Mouse.click?都可以

比如Mouse.press?(1)应该就是判断左键是否按下

楼上水帖自重
RGDirect - DirectX驱动的RGSS,点我了解.
RM全系列成套系统定制请联系QQ1213237796
不接受对其他插件维护的委托
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
131 小时
注册时间
2010-6-24
帖子
623
4
发表于 2010-12-9 15:19:29 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
60
在线时间
305 小时
注册时间
2009-8-21
帖子
119
5
 楼主| 发表于 2010-12-9 20:24:36 | 只看该作者
fux2 发表于 2010-12-9 13:21
定义写的很清楚了。用Mouse.press?或Mouse.click?都可以

比如Mouse.press?(1)应该就是判断左键是否按下

那在事件里应该怎样写?
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
466 小时
注册时间
2006-2-25
帖子
1863
6
发表于 2010-12-9 22:34:42 | 只看该作者
本帖最后由 诡异の猫 于 2010-12-9 22:37 编辑

他的左键不知道是不是0x01呃。。如果是的话
在事件里的话就是
条件分歧——4——脚本——Mouse.click?(0x01)

点评

乃以为这是分割定义么  发表于 2010-12-10 09:26

评分

参与人数 1星屑 +530 收起 理由
夕阳武士 + 530 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
60
在线时间
305 小时
注册时间
2009-8-21
帖子
119
7
 楼主| 发表于 2010-12-10 12:11:42 | 只看该作者
诡异の猫 发表于 2010-12-9 22:34
他的左键不知道是不是0x01呃。。如果是的话
在事件里的话就是
条件分歧——4——脚本——Mouse.click?(0x01 ...

太感谢啦!OK结贴
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-29 03:19

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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