Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. ;;
  2. ;; Emulate_Scrolling_Middle_Button.ahk
  3. ;; Author: Erik Elmore <erik@ironsavior.net>
  4. ;; Version: 1.1 (Aug 16, 2005)
  5. ;;
  6. ;; Enables you to use any key with cursor movement
  7. ;; to emulate a scrolling middle button. While
  8. ;; the TriggerKey is held down, you may move the
  9. ;; mouse cursor up and down to send scroll wheel
  10. ;; events. If the cursor does not move by the
  11. ;; time the TriggerKey is released, then a middle
  12. ;; button click is generated. I wrote this for my
  13. ;; 4-button Logitech Marble Mouse (trackball),
  14. ;; which has no middle button or scroll wheel.
  15. ;;
  16.  
  17. ;; Configuration
  18.  
  19. ;#NoTrayIcon
  20.  
  21. ;; Higher numbers mean less sensitivity
  22. esmb_Threshold = 10
  23.  
  24. ;; This key/Button activates scrolling
  25. esmb_TriggerKey = XButton2
  26.  
  27. ;; End of configuration
  28.  
  29. #Persistent
  30. CoordMode, Mouse, Screen
  31. Hotkey, %esmb_TriggerKey%, esmb_TriggerKeyDown
  32. HotKey, %esmb_TriggerKey% Up, esmb_TriggerKeyUp
  33. esmb_KeyDown = n
  34. SetTimer, esmb_CheckForScrollEventAndExecute, 10
  35. return
  36.  
  37. esmb_TriggerKeyDown:
  38. esmb_Moved = n
  39. esmb_FirstIteration = y
  40. esmb_KeyDown = y
  41. MouseGetPos, esmb_OrigX, esmb_OrigY
  42. esmb_AccumulatedDistance = 0
  43. return
  44.  
  45. esmb_TriggerKeyUp:
  46. esmb_KeyDown = n
  47. ;; Send a middle-click if we did not scroll
  48. if esmb_Moved = n
  49. ;;MouseClick, Middle
  50. MouseClick, X2
  51. return
  52.  
  53. esmb_CheckForScrollEventAndExecute:
  54. if esmb_KeyDown = n
  55. return
  56.  
  57. MouseGetPos,, esmb_NewY
  58. esmb_Distance := esmb_NewY - esmb_OrigY
  59. if esmb_Distance
  60. esmb_Moved = y
  61.  
  62. esmb_AccumulatedDistance := (esmb_AccumulatedDistance + esmb_Distance)
  63. esmb_Ticks := (esmb_AccumulatedDistance // esmb_Threshold) ; floor divide
  64. esmb_AccumulatedDistance := (esmb_AccumulatedDistance - (esmb_Ticks * esmb_Threshold))
  65. esmb_WheelDirection := "WheelDown"
  66. if (esmb_Ticks < 0) {
  67. esmb_WheelDirection := "WheelUp"
  68. esmb_Ticks := (-1 * esmb_Ticks)
  69. }
  70.  
  71. ;; Do not send clicks on the first iteration
  72. if esmb_FirstIteration = y
  73. esmb_FirstIteration = n
  74. else {
  75. Loop % esmb_Ticks {
  76. MouseClick, %esmb_WheelDirection%
  77. }
  78. }
  79.  
  80. MouseMove,esmb_OrigX,esmb_OrigY,0
  81. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement