1

Тема: AHK: Множественные действия правой кнопки мыши

Код является слегка непричёсанным (уж извиняйте) фрагментом программы RadialMenu.
При зажатой правой кнопке доступны следующие жесты:

вверх/вниз — блокнот/окно-gui;
вправо/влево — посылает нажатия клавиш вправо/влево (удобно для перемотки видео);
вправо и вниз закомментировано.


#SingleInstance force

RMShowHotkey =		RButton
RMShowMethod =		D
RSMShowHotkey =	LButton

MenuBackgroundWidth =	225	
MenuBackgroundHeight =	225	


Hotkey, IfWinNotActive, ahk_group BlackList
Hotkey, *%RMShowHotkey%, RMShowHotkey, on
Hotkey, IfWinNotActive

Hotkey, IfWinExist, RMItem1     ; at least Item1 in main menu must be shown to enable Radial submenu show Hotkey
Hotkey, %RSMShowHotkey%, RSMShowHotkey
Hotkey, IfWinExist
return



;===Main menu show Hotkey========================================================================
RMShowHotkey:
Hotkey, %RMShowHotkey%, RMShowHotkey, off


; Collect useful informations: OrigWinID, OrigWinTitle, OrigWinClass
MouseGetPos, mx1, my1, OrigWinID
WinGetTitle, OrigWinTitle, ahk_id %OrigWinID%
WinGetClass, OrigWinClass, ahk_id %OrigWinID%

mxInit := mx1
myInit := my1

;===Prepare background postiton===
RMBX := mx1-MenuBackgroundWidth/2, RMBY := my1-MenuBackgroundHeight/2
Gui, 99: Show, hide x%RMBX% y%RMBY%, RMBackground        ; RMBackground


if RMShowMethod is not digit    ; than RMShowMethod is mouse gesture
{
   ;===Recognize gesture===
   Loop
   {
      if !(GetKeyState(RMShowHotkey, "p"))
      {
         if Gesture =
         {
            EmptyGestureVars()
            SendInput, {%RMShowHotkey%}
            Hotkey, *%RMShowHotkey%, RMShowHotkey, on
            Return
         }
         MG_%Gesture%()
         EmptyGestureVars()
         Hotkey, *%RMShowHotkey%, RMShowHotkey, on
         Return
      }
      Sleep, 20   ; prevents high CPU load
      MouseGetPos, EndX, EndY
      Radius := GetRadius(mx1, my1, EndX, EndY)
      if (Radius < 109)
      Continue
      
      Angle := GetAngle(mx1, my1, EndX, EndY)
      MouseGetPos, mx1, my1
      CurGesture := GetGesture(Angle)
      
      if !(CurGesture = LastGesture)
      {
         Gesture .= CurGesture
         LastGesture := CurGesture
         {
            if (StrLen(Gesture) > 3)   ; limit to 3 moves 
            {
               EmptyGestureVars()
               Progress, m2 b fs10 zh0 w80 WMn700, Gesture canceled
               Sleep, 200
               KeyWait, %RMShowHotkey%, u
               Progress, off
               Hotkey, *%RMShowHotkey%, RMShowHotkey, on
               Return
            }
         }
      }
      if Gesture = %RMShowMethod%   ; Call RM to show
      break
   }
   EmptyGestureVars()
}
Else    ; than RMShowMethod is show delay
{
   While (A_TimeSinceThisHotkey < RMShowMethod)       ; ShowDelay sleep...
   {
      Sleep, 20   ; prevents high CPU load
      if not (GetKeyState(RMShowHotkey,"p"))
      {
tooltip ggggggggggggg
sleep 600
tooltip
         SendInput, {%RMShowHotkey%}
         Hotkey, *%RMShowHotkey%, RMShowHotkey, on
         Return
      }
   }
}


Gui, 99: -Caption +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs +Disabled   ; +Disabled suggested by bmn_ (Thanks!)


Gui, 99: Show, NA x%RMBX% y%RMBY% w255 h255,RMBackground      ; RMBackground
Loop, %MMTotalButtons%                            ; RMItem (s)
Gui, %A_Index%: Show, NA    
if RMShowMethod is not digit    ; than RMShowMethod is mouse gesture, therefore return mouse in initial position
{
   Sleep, 30   ; short break before returning mouse
   MouseMove, mxInit, myInit   ; return in initial position
}



KeyWait, %RMShowHotkey%, u      ; waits RMShowHotkey to be released
Hotkey, *%RMShowHotkey%, RMShowHotkey, on

LastRMItemNum = 


; if problems with run occur (if Gui, 98 is still not hidden), put a short sleep here
MouseGetPos, , , WinID
WinGetTitle, WinTitle, ahk_id %WinID%
if WinTitle contains RMItem     ; RMShowHotkey released on item
{
   
   Gosub, RadialMenuClose

}
else                            ; RMShowHotkey not released on item - just close menu
{
   Gosub, RadialMenuClose
}
Return


RSMShowHotkey:

return


RadialMenuClose:
Gui, 99: Hide
Return


GetGesture(Angle)    ; by Learning one
{
   Loop, 4
   {
      if (Angle <= 90*A_Index-45)
      {
         Sector := A_Index
         Break
      }
      Else if (A_Index = 4)
      Sector := 1
   }
   if Sector = 1
   Return "U"
   else if Sector = 2
   Return "R"
   else if Sector = 3
   Return "D"
   else if Sector = 4
   Return "L"
}

GetAngle(ByRef StartX, ByRef StartY, ByRef EndX, ByRef EndY)    ; by Learning one
{
   x := EndX-StartX, y := EndY-StartY
   if x = 0
   {
      if y > 0
      return 180
      Else if y < 0
      return 360
      Else
      return
   }
   Angle := ATan(y/x)*57.295779513
   if x > 0
   return Angle + 90
   Else
   return Angle + 270	
}


GetRadius(ByRef StartX, ByRef StartY, ByRef EndX, ByRef EndY)      ; by Learning one
{
   a := Abs(endX-startX), b := Abs(endY-startY), Radius := Sqrt(a*a+b*b)
   Return Radius    
}


EmptyGestureVars()    ; by Learning one
{
   global
   EndX =
   EndY =
   Gesture =
   LastGesture =
}


;===Mouse gesture definitions=========================================================================

MG_U() {
   Run, notepad	; this is just example to produce "it works" impression when you try Radial menu for the first time.
}
MG_R() {
  send, {right}

}
MG_L() {
  send, {left}

}
;MG_RD() {
;  ActiveWinID := WinExist("A")
;  WinClose, ahk_id %ActiveWinID%
;}


^1::exitapp

Во весь свой рост встала необходимость срастить его вот с таким незамысловатым:


$RButton::
SendInput, {RButton}
Return

Возможно ли (не меняя последний)?

2

Re: AHK: Множественные действия правой кнопки мыши

А перекроить горячую клавишу из


Hotkey, *%RMShowHotkey%, RMShowHotkey, on/off

в


$RButton::

можно?