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

Project1

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

[已经解决] 请教获得鼠标滚轮滚动的方法

[复制链接]

Lv1.梦旅人

Dancer-

梦石
0
星屑
55
在线时间
76 小时
注册时间
2006-11-9
帖子
3551

开拓者贵宾

跳转到指定楼层
1
发表于 2014-1-26 11:50:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 叶舞枫 于 2014-1-30 12:23 编辑

如题。使用现有的鼠标脚本只能获得鼠标指针的相对坐标。。
现在因为一些功能想要判断鼠标中部滚轮的滚动情况,查API表也没找到什么有价值的信息

请问应该如何实现呢?谢谢

Lv2.观梦者 (暗夜天使)

梦石
0
星屑
266
在线时间
2355 小时
注册时间
2009-3-13
帖子
2309

贵宾

2
发表于 2014-1-26 18:28:49 | 只看该作者
本帖最后由 Sion 于 2014-1-26 18:31 编辑

通过拦截窗口消息获取,这里有源码:http://rpg.blue/thread-347535-1-1.html
回复 支持 反对

使用道具 举报

Lv1.梦旅人

Dancer-

梦石
0
星屑
55
在线时间
76 小时
注册时间
2006-11-9
帖子
3551

开拓者贵宾

3
 楼主| 发表于 2014-1-26 22:23:53 | 只看该作者
Sion 发表于 2014-1-26 18:28
通过拦截窗口消息获取,这里有源码:http://rpg.blue/thread-347535-1-1.html

谢谢! 但是我看了一下是RMVA的脚本。。。
我这边做的是RMXP的,自己试着改了好久总是不成功…
所以希望您能否帮忙修改一下呢,其实就需要鼠标完整功能(点击、获得坐标、滚轮)这部分就好,真的非常感谢!!

点评

不知道为啥@不到,见楼下  发表于 2014-1-28 22:48
@Sion 好的!非常感谢!  发表于 2014-1-26 22:43
不急的话就等几天。  发表于 2014-1-26 22:41
回复 支持 反对

使用道具 举报

Lv2.观梦者 (暗夜天使)

梦石
0
星屑
266
在线时间
2355 小时
注册时间
2009-3-13
帖子
2309

贵宾

4
发表于 2014-1-28 17:56:13 | 只看该作者
本帖最后由 Sion 于 2014-1-28 22:48 编辑
叶舞枫 发表于 2014-1-26 22:23
谢谢! 但是我看了一下是RMVA的脚本。。。
我这边做的是RMXP的,自己试着改了好久总是不成功…
所以希望 ...


弄好了
会不会用 API 调用函数?
SiNovaXP.rar (101.42 KB, 下载次数: 85)
GetMousePos   p(II)    v       获取鼠标坐标
MouseZ         v       i       鼠标滚轮状态,上滚此值 +1,下滚 -1
MouseZReset    v       v       重置鼠标滚轮状态为 0
MouseSetPos    ii      v       把鼠标设置到 x, y 处



--------edited-----------
@叶舞枫
对了运行以前要先加载一下 dll:
  1. $DLLHOOK = Win32API.new('dll名', 'Hook', 'v', 'l')
  2. $DLLHOOK.call
复制代码
其它的 dll 函数也像这样调用
回复 支持 反对

使用道具 举报

Lv1.梦旅人

Dancer-

梦石
0
星屑
55
在线时间
76 小时
注册时间
2006-11-9
帖子
3551

开拓者贵宾

5
 楼主| 发表于 2014-1-29 11:30:19 | 只看该作者
不知道为什么还是不行的样子。。。
将修改好的dll放在游戏根目录下后,我在游戏里写了这样的代码:
  1. $mousewhell = Win32API.new('SiNovaXP', 'MouseZ', 'v', 'i')
  2. $mouse_z = $mousewhell.call
复制代码
结果无论怎么调用,返回值永远都是0.……
所以…不好意思地说……能提供个小范例么?真的很感谢 ><


ps:游戏里含有一个传统的调用鼠标的脚本,贴在下面:

  1. #==============================================================================
  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  3. #==============================================================================

  4. $敌人选框扩大 = 20
  5. $角色选框扩大 = 30

  6. #==============================================================================
  7. # API调用
  8. #==============================================================================
  9. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  10. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  11. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  12. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  13. $Window_HWND = $GetActiveWindow.call
  14. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  15. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
  16. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)
  17. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)
  18. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')
  19. #$Window_HWND = $FindWindow.call(nil, 'mousetry')

  20. module Mouse  
  21.   LEFT = 0x01
  22.   RIGHT = 0x02

  23.   def self.init(sprite = nil)
  24. #   $HookStart.call($Window_HWND)
  25.     $ShowCursor.call(0)
  26.    
  27.     @show_cursor = false
  28.    
  29.     @mouse_sprite = Sprite.new
  30.     @mouse_sprite.z = 99999
  31.     @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mamisan.png')
  32.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))

  33.     @left_press = false
  34.     @right_press = false
  35.     @left_trigger = false
  36.     @right_trigger = false
  37.     @left_repeat = false
  38.     @right_repeat = false
  39.     @click_lock = false
  40.    
  41.     update
  42.   end
  43.   def self.exit
  44.     @mouse_sprite.bitmap.dispose
  45.     @mouse_sprite.dispose
  46.     @show_cursor = true
  47. #    $HookEnd.call
  48.     $ShowCursor.call(1)
  49.   end
  50.   def self.mouse_debug
  51.     return @mouse_debug.bitmap
  52.   end
  53.   
  54.   
  55.   
  56.   def self.update
  57.    
  58.     if $chai == 1
  59.       return 0
  60.     end
  61.    
  62.    
  63.     left_down = $GetKeyState.call(0x01)
  64.     right_down = $GetKeyState.call(0x02)
  65.    
  66.     @click_lock = false
  67.     mouse_x, mouse_y = self.get_mouse_pos
  68.     if @mouse_sprite != nil
  69.       @mouse_sprite.x = mouse_x
  70.       @mouse_sprite.y = mouse_y
  71.     end
  72.     if left_down[7] == 1
  73.       @left_repeat = (not @left_repeat)
  74.       @left_trigger = (not @left_press)
  75.       @left_press = true
  76.     else
  77.       @left_press = false
  78.       @left_trigger = false
  79.       @left_repeat = false
  80.     end
  81.     if right_down[7] == 1
  82.       @right_repeat = (not @right_repeat)
  83.       @right_trigger = (not @right_press)
  84.       @right_press = true
  85.     else
  86.       @right_press = false
  87.       @right_trigger = false
  88.       @right_repeat = false
  89.     end
  90.   end
  91.   
  92.   
  93.   
  94.   
  95.   def self.get_mouse_pos
  96.    
  97.    
  98.     point_var = [0, 0].pack('ll')
  99.    
  100.    
  101.     if $GetCursorPos.call(point_var) != 0
  102.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  103.         x, y = point_var.unpack('ll')
  104.         if (x < 0) or (x > 10000) then x = 0 end
  105.         if (y < 0) or (y > 10000) then y = 0 end
  106.         if x > 800 then x = 800 end
  107.         if y > 450 then y = 450 end
  108.         return x, y
  109.       else
  110.         return 0, 0
  111.       end
  112.     else
  113.       return 0, 0
  114.     end
  115.   end
  116.   def self.press?(mouse_code)
  117.     if mouse_code == LEFT
  118.       if @click_lock
  119.         return false
  120.       else
  121.         return @left_press
  122.       end
  123.     elsif mouse_code == RIGHT
  124.       return @right_press
  125.     else
  126.       return false
  127.     end
  128.   end
  129.   def self.trigger?(mouse_code)
  130.     if mouse_code == LEFT
  131.       if @click_lock
  132.         return false
  133.       else
  134.         return @left_trigger
  135.       end
  136.     elsif mouse_code == RIGHT
  137.       return @right_trigger
  138.     else
  139.       return false
  140.     end
  141.   end
  142.   def self.repeat?(mouse_code)
  143.     if mouse_code == LEFT
  144.       if @click_lock
  145.         return false
  146.       else
  147.         return @left_repeat
  148.       end
  149.     elsif mouse_code == RIGHT
  150.       return @right_repeat
  151.     else
  152.       return false
  153.     end
  154.   end
  155.   def self.click_lock?
  156.     return @click_lock
  157.   end
  158.   def self.click_lock
  159.     @click_lock = true
  160.   end
  161.   def self.click_unlock
  162.     @click_lock = false
  163.   end
  164. end
  165. module Input
  166.   if @self_update == nil
  167.     @self_update = method('update')
  168.     @self_press = method('press?')
  169.     @self_trigger = method('trigger?')
  170.     @self_repeat = method('repeat?')
  171.   end
  172.   def self.update
  173.     @self_update.call
  174.     Mouse.update
  175.   end
  176.   def self.press?(key_code)
  177.     if @self_press.call(key_code)
  178.       return true
  179.     end
  180.     if key_code == C
  181.       return Mouse.press?(Mouse::LEFT)
  182.     elsif key_code == B
  183.       return Mouse.press?(Mouse::RIGHT)
  184.     else
  185.       return @self_press.call(key_code)
  186.     end
  187.   end
  188.   def self.trigger?(key_code)
  189.     if @self_trigger.call(key_code)
  190.       return true
  191.     end
  192.     if key_code == C
  193.       return Mouse.trigger?(Mouse::LEFT)
  194.     elsif key_code == B
  195.       return Mouse.trigger?(Mouse::RIGHT)
  196.     else
  197.       return @self_trigger.call(key_code)
  198.     end
  199.   end
  200.   def self.repeat?(key_code)
  201.     if @self_repeat.call(key_code)
  202.       return true
  203.     end
  204.     if key_code == C
  205.       return Mouse.repeat?(Mouse::LEFT)
  206.     elsif key_code == B
  207.       return Mouse.repeat?(Mouse::RIGHT)
  208.     else
  209.       return @self_repeat.call(key_code)
  210.     end
  211.   end
  212. end
  213. class Window_Selectable
  214.   if @self_alias == nil
  215.     alias self_update update
  216.     @self_alias = true
  217.   end
  218.   def update
  219.     #self.cursor_rect.empty
  220.     self_update
  221.     if self.active and @item_max > 0
  222.       index_var = @index
  223.       tp_index = @index
  224.       mouse_x, mouse_y = Mouse.get_mouse_pos
  225.       mouse_not_in_rect = true
  226.       for i in 0...@item_max
  227.         [url=home.php?mod=space&uid=370741]@Index[/url] = i
  228.         update_cursor_rect
  229.         top_x = self.cursor_rect.x + self.x + 16
  230.         top_y = self.cursor_rect.y + self.y + 16
  231.         bottom_x = top_x + self.cursor_rect.width
  232.         bottom_y = top_y + self.cursor_rect.height
  233.         if (mouse_x > top_x) and (mouse_y > top_y) and
  234.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  235.           mouse_not_in_rect = false
  236.           if tp_index != @index
  237.             tp_index = @index
  238.             $game_system.se_play($data_system.cursor_se)
  239.           end
  240.           break
  241.         end
  242.       end
  243.       if mouse_not_in_rect
  244.         @index = index_var
  245.         update_cursor_rect
  246.         Mouse.click_lock
  247.       else
  248.         Mouse.click_unlock               
  249.       end
  250.     end
  251.   end
  252. end
  253. class Window_NameInput
  254.   if @self_alias == nil
  255.     alias self_update update
  256.     @self_alias = true
  257.   end
  258.   def update
  259.     #self.cursor_rect.empty
  260.     self_update
  261.     if self.active
  262.       index_var = @index
  263.       mouse_x, mouse_y = Mouse.get_mouse_pos
  264.       mouse_not_in_rect = true
  265.       for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  266.         @index = i
  267.         update_cursor_rect
  268.         top_x = self.cursor_rect.x + self.x + 16
  269.         top_y = self.cursor_rect.y + self.y + 16
  270.         bottom_x = top_x + self.cursor_rect.width
  271.         bottom_y = top_y + self.cursor_rect.height
  272.         #
  273.         if (mouse_x > top_x) and (mouse_y > top_y) and
  274.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  275.           mouse_not_in_rect = false
  276.           break
  277.         end
  278.       end
  279.       if mouse_not_in_rect
  280.         @index = index_var
  281.         update_cursor_rect
  282.         Mouse.click_lock
  283.       else
  284.         Mouse.click_unlock
  285.       end
  286.     end
  287.   end
  288. end
  289. class Window_InputNumber
  290.   if @self_alias == nil
  291.     alias self_update update
  292.     @self_alias = true
  293.   end
  294.   def update
  295.     #self.cursor_rect.empty
  296.     self_update
  297.     mouse_x, mouse_y = Mouse.get_mouse_pos
  298.     if self.active and @digits_max > 0
  299.       index_var = @index
  300.       mouse_not_in_rect = true
  301.       for i in 0...@digits_max
  302.         @index = i
  303.         update_cursor_rect
  304.         top_x = self.cursor_rect.x + self.x + 16
  305.         bottom_x = top_x + self.cursor_rect.width
  306.         #
  307.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  308.           mouse_not_in_rect = false
  309.           break
  310.         end
  311.       end
  312.       if mouse_not_in_rect
  313.         @index = index_var
  314.         update_cursor_rect
  315.         Mouse.click_lock
  316.       else
  317.         Mouse.click_unlock
  318.       end
  319.     end
  320.     if @last_mouse_y == nil
  321.       @last_mouse_y = mouse_y
  322.     end
  323.     check_pos = (@last_mouse_y - mouse_y).abs
  324.     if check_pos > 10
  325.       $game_system.se_play($data_system.cursor_se)
  326.       place = 10 ** (@digits_max - 1 - @index)
  327.       n = [url=home.php?mod=space&uid=27178]@Number[/url] / place % 10
  328.       @number -= n * place
  329.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  330.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  331.       @number += n * place
  332.       refresh
  333.       @last_mouse_y = mouse_y
  334.     end
  335.   end
  336. end
  337. class Scene_File
  338.   if @self_alias == nil
  339.     alias self_update update
  340.     @self_alias = true
  341.   end
  342.   def update
  343.     mouse_x, mouse_y = Mouse.get_mouse_pos
  344.     Mouse.click_lock
  345.     idx = 0
  346.     for i in @savefile_windows
  347.       top_x = i.x + 16
  348.       top_y = i.y + 16
  349.       bottom_x = top_x + i.width
  350.       bottom_y = top_y + i.height
  351.       if (mouse_x > top_x) and (mouse_y > top_y) and
  352.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  353.         i.selected = true
  354.         if @file_index != idx
  355.           @file_index = idx
  356.           $game_system.se_play($data_system.cursor_se)
  357.         end            
  358.         Mouse.click_unlock
  359.       else
  360.         i.selected = false
  361.       end
  362.       idx += 1
  363.     end
  364.     self_update
  365.   end
  366. end
  367. class Arrow_Enemy
  368.   if @self_alias == nil
  369.     alias self_update update
  370.     @self_alias = true
  371.   end
  372.   def update
  373.     mouse_x, mouse_y = Mouse.get_mouse_pos
  374.     idx = 0
  375.     for i in $game_troop.enemies do
  376.       if i.exist?
  377.         top_x = i.screen_x - self.ox
  378.         top_y = i.screen_y - self.oy
  379.         bottom_x = top_x + self.src_rect.width
  380.         bottom_y = top_y + self.src_rect.height
  381.         if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  382.            (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  383.           if @index != idx
  384.             $game_system.se_play($data_system.cursor_se)
  385.             @index = idx
  386.           end
  387.         end
  388.       end
  389.       idx += 1
  390.     end
  391.     self_update
  392.   end
  393. end
  394. class Arrow_Actor
  395.   if @self_alias == nil
  396.     alias self_update update
  397.     @self_alias = true
  398.   end
  399.   def update
  400.     mouse_x, mouse_y = Mouse.get_mouse_pos
  401.     idx = 0
  402.     for i in $game_party.actors do
  403.       if i.exist?
  404.         top_x = i.screen_x - self.ox
  405.         top_y = i.screen_y - self.oy
  406.         bottom_x = top_x + self.src_rect.width
  407.         bottom_y = top_y + self.src_rect.height
  408.         if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  409.            (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  410.           if @index != idx
  411.             $game_system.se_play($data_system.cursor_se)
  412.             @index = idx
  413.           end
  414.         end
  415.       end
  416.       idx += 1
  417.     end
  418.     self_update
  419.   end
  420. end
  421. class Game_Player
  422.   if @self_alias == nil
  423.     alias self_update update
  424.     @self_alias = true
  425.   end
  426.   def update
  427.     mouse_x, mouse_y = Mouse.get_mouse_pos

  428.     if @last_move_x == nil
  429.       @last_move_x = false
  430.     end
  431.     if Mouse.press?(Mouse::LEFT)
  432.       last_moving = moving?
  433.       last_direction = @direction
  434.       unless moving? or $game_system.map_interpreter.running? or
  435.              @move_route_forcing or $game_temp.message_window_showing
  436.         last_x = @x
  437.         if @last_move_x
  438.           @last_move_x = false
  439.         elsif mouse_x > screen_x + 16
  440.           move_right
  441.         elsif mouse_x < screen_x - 16
  442.           move_left
  443.         end
  444.         last_y = @y
  445.         if last_x != @x
  446.           @last_move_x = true
  447.         elsif mouse_y > screen_y
  448.           move_down
  449.         elsif mouse_y < screen_y - 32
  450.           move_up
  451.         end
  452.         if last_y != @y
  453.           @last_move_x = false
  454.         elsif not @last_move_x
  455.           case last_direction
  456.           when 2
  457.             turn_down
  458.           when 4
  459.             turn_left
  460.           when 6
  461.             turn_right
  462.           when 8
  463.             turn_up
  464.           end
  465.         end
  466.       end
  467.     end
  468.     self_update
  469.   end
  470. end
  471. Mouse.init
  472. END { Mouse.exit }




  473. #==============================================================================
  474. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  475. #==============================================================================
复制代码
回复 支持 反对

使用道具 举报

Lv2.观梦者 (暗夜天使)

梦石
0
星屑
266
在线时间
2355 小时
注册时间
2009-3-13
帖子
2309

贵宾

6
发表于 2014-1-30 00:20:42 | 只看该作者
Project2.rar (288.6 KB, 下载次数: 113)

创建了个控制台,滚鼠标就能看到 z 值变化了

评分

参与人数 1星屑 +400 收起 理由
叶舞枫 + 400 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

Lv1.梦旅人

Dancer-

梦石
0
星屑
55
在线时间
76 小时
注册时间
2006-11-9
帖子
3551

开拓者贵宾

7
 楼主| 发表于 2014-1-30 12:22:17 | 只看该作者
Sion 发表于 2014-1-30 00:20
创建了个控制台,滚鼠标就能看到 z 值变化了

原来是忘记用HOOK加载了,Σ( ° △ °|||)︴
非常感谢!控制台的调试方法我也顺带学习了!!这个真的很方便w

再次感谢w
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-22 20:21

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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