Тема: AHK: Управление клавиатурными стрелочками с помощью мыши
Доброго времени суток. Подскажите пожалуйста как можно реализовать управление клавиатурными стрелочками с помощью движений мыши в соответствующем направлении .
Вы не вошли. Пожалуйста, войдите или зарегистрируйтесь.
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться
Доброго времени суток. Подскажите пожалуйста как можно реализовать управление клавиатурными стрелочками с помощью движений мыши в соответствующем направлении .
MouseGetPos.
Вот держи, переделай под свои нужды:
#NoEnv
#SingleInstance,Force
SetTitleMatchMode,2
SetBatchLines,-1
CoordMode,Mouse,Screen
CoordMode,ToolTip
SetKeyDelay,0
SendMode,Input
; Настройки:
class=EPSX ; класс окна.
; клавиши.
Mouse_Up=up
Mouse_Down=down
Mouse_left=left
Mouse_Right=right
Mouse_LB=vk58 ; X
Mouse_RB=vk59 ; Y
Mouse_MB=vk5a ; Z
Delay=20 ; чувствительность.
coeffx=1.5 ; коэффициенты для мыши.
coeffy=1.5
Gui=0 ; прицел - требуется файл "xros.png", содержащий изображение прицела с прозрачным фоном.
Xoffset=-10 ; смещение прицела относительно центра экрана.
Yoffset=5
w=32 ; Размеры прицела.
h=32
; Начало.
if gui
{
x:=(a_screenwidth/2-1-w/2)+Xoffset
y:=(a_screenheight/2-1-h/2)+Yoffset
Gui,-Caption +AlwaysOnTop +E0x08000020 +Lastfound
Gui,Margin,0,0
Gui,Add,Picture,w%w% h%h%,%a_scriptdir%\xros.png
Gui,Show,NA x%x% y%y% w%w% h%h%
ID:=WinExist()
WinSet,ExStyle,+0x20,ahk_id %ID%
WinSet,TransColor,0xF0F0F0,ahk_id %ID%
Gui,hide
}
loop ; ШИМ мышь-клавиши
{
if !WinActive("ahk_class " . class)
{
if gui
gui,hide
sleep,1000
continue
}
mousemove,a_screenwidth/2,a_screenheight/2,0
DllCall("Sleep",UInt,Delay)
mousegetpos,x1,y1
x:=a_screenwidth/2-x1, y:=a_screenheight/2-y1
; ------------------------------- право лево ----------------------------------
if (x!=0 and !dooncex)
{
dooncex=1
pressx:=abs(x) ; x>0 = left; x<0 = right
xx:=x
send,% "{" Mouse_left " " (x<0 ? "Up" : "Down") "}{" Mouse_right " " (x>0 ? "Up" : "Down") "}"
}
else if (x=0 and dooncex)
{
dooncex=
send,% "{" Mouse_left " up}{" Mouse_right " up}"
}
if ((pressx:=pressx-coeffx)<0 and pressx>-coeffx-1)
{
dooncex=
send,% "{" (xx>0 ? Mouse_left : Mouse_right) " up}"
}
; ------------------------------- верх низ ----------------------------------
if (y!=0 and !dooncey)
{
dooncey=1
pressy:=abs(y) ; y>0 = up; y<0 = Down
yy:=y
send,% "{" Mouse_Up " " (y<0 ? "Up" : "Down") "}{" Mouse_Down " " (y>0 ? "Up" : "Down") "}"
}
else if (y=0 and dooncey)
{
dooncey=
send,% "{" Mouse_Up " up}{" Mouse_Down " up}"
}
if ((pressy:=pressy-coeffy)<0 and pressy>-coeffy-1)
{
dooncey=
send,% "{" (yy>0 ? Mouse_Up : Mouse_Down) " up}"
}
; ------------------------------- gui update ----------------------------------
if (gui and !showw:=showw>50 ? 0 : showw="" ? 1 : showw+1)
{
Gui, Show, na
WinSet, AlwaysOnTop, On,ahk_id %ID%
}
}
return
#if WinActive("ahk_class " . class)
lbutton::
send,{%Mouse_LB% down}
return
lbutton up::
send,{%Mouse_LB% up}
return
rbutton::
send,{%Mouse_RB% down}
return
rbutton up::
send,{%Mouse_RB% up}
return
mbutton::
send,{%Mouse_MB% down}
return
mbutton up::
send,{%Mouse_MB% up}
return
#if
!esc:: ; Alt+Esc
exitapp
Доброго времени суток. Уважаемый Alectric скрипт который вы предоставили работает как то неправильно картинка крутится как вертолёт в разные стороны. Всего лишь нужно сделать, при
движении мыши влево, нажать стрелку влево на клавиатуре и соответственно при
движении мыши вправо, нажать стрелку вправо с задержкой 500 (мс). Помогите пожалуйста .
Вот нашёл на буржуйском сайте. Всё вроде бы работает но не так плавно как хотелось бы. Задержки пробовал менять не помогло, может что нибудь добавить или наоборот . Да кстати разобрался насчёт кручения картинки (вертолётом) это происходит из за параметра (-1) в этой строке "SetMouseDelay, -1" достаточно поменять значение на (1) и всё кручения прекращаются.
Hover = ~F1
; Select Hotkey to active StickMode:
Stick = ~F2
; Select Hotkey show Zones Guidelines:
ShowZones = CapsLock
; Select optional Hotkey reset mouse to Center:
Center = MButton
; Set Horizontal & Vertical Dead Zone Ranges in pixels:
DeadZoneRangeX := 600
DeadZoneRangeY := 500
KeySet =
( ; Set the keys that will be sent for each of the eight zones of the screen:
Up = Up
Down = Down
Left = Left
Right = Right
UpLeft = Up & Left
UpRight = Up & Right
DownLeft = Down & Left
DownRight = Down & Right
)
; ########## End of configurations! ##########
; Parse KeySet and assign variables to the keys:
Loop, Parse, KeySet, `n
{
Loop, Parse, A_LoopField, =, %A_Space%
If Mod(A_Index, 2)
Key := A_LoopField
Else
{
%Key% := A_LoopField
StringSplit, %Key%, A_LoopField, &, %A_Space%
}
}
#SingleInstance, Force
SendMode, Input
SetKeyDelay, -1
SetMouseDelay, 1
SetBatchLines, -1 ; How often the script should sleep (how fast it will run)
CoordMode, Mouse, Screen
; Get coordinates for the center of the screen to create a Dead Zone:
DeadZoneX := A_ScreenWidth / 2
DeadZoneY := A_ScreenHeight / 2
; Activate Hotkeys:
Hotkey, %Hover%, Hover, On
Hotkey, %Stick%, Stick, On
Hotkey, %ShowZones%, ShowZones, On
Try Hotkey, %Center%, CenterMouse, On
; Create a rectangle to show Dead Zone:
A := DeadZoneRangeX*2, B := DeadZoneRangeY*2, C := A-2, D := B-2
Gui, -Caption +ToolWindow +LastFound +AlwaysOnTop
Gui, Color, Red
Gui, +LastFound
WinSet, Region, 0-0 %A%-0 %A%-%B% 0-%B% 0-0 2-2 %C%-2 %C%-%D% 2-%D% 2-2
GoSub, ShowZones
Display := !Display
SetTimer, RemoveTip, -1500
return
Hover:
StickMode := False
SetTimer, WatchMouse, % (HoverMode := !HoverMode) ? 0 : "Off"
Loop, % %hKeys%0
Send, % (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
TrayTip,, % (HoverMode) ? "HoverMode On" : "HoverMode Off"
return
Stick:
HoverMode := False
SetTimer, WatchMouse, % (StickMode := !StickMode) ? 0 : "Off"
Loop, % %hKeys%0
Send, % (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
TrayTip,, % (StickMode) ? "StickMode On" : "StickMode Off"
return
ShowZones:
If (Display := !Display)
{
Gui, Show, % "NA x" DeadZoneX - DeadZoneRangeX "y" DeadZoneY - DeadZoneRangeY "w" DeadZoneRangeX * 2 "h" DeadZoneRangeY * 2
Tooltip, Dead Zone, % DeadZoneX-25, % DeadZoneY-25, 1
Tooltip, % Up, % DeadZoneX-25, % 0, 2
Tooltip, % Down, % DeadZoneX-25, % A_ScreenHeight, 3
Tooltip, % Left, % 0, % DeadZoneY-25, 4
Tooltip, % Right, % A_ScreenWidth, % DeadZoneY-25, 5
Tooltip, % UpLeft, % 0, % 0, 6
Tooltip, % UpRight, % A_ScreenWidth, % 0, 7
Tooltip, % DownLeft, % 0, % A_ScreenHeight, 8
Tooltip, % DownRight, % A_ScreenWidth, % A_ScreenHeight, 9
}
Else
GoSub, RemoveTip
return
RemoveTip:
Gui, Cancel
Tooltip,,,,1
Tooltip,,,,2
Tooltip,,,,3
Tooltip,,,,4
Tooltip,,,,5
Tooltip,,,,6
Tooltip,,,,7
Tooltip,,,,8
Tooltip,,,,9
return
CenterMouse:
Click, %DeadZoneX%, %DeadZoneY%, 0
return
WatchMouse:
MouseGetPos, pX, pY
If StickMode
{
If ((pX = 0) || (pX = A_ScreenWidth-1))
|| ((pY = 0) || (pY = A_ScreenHeight-1))
GoSub, CenterMouse
Sleep, 250
MouseGetPos, cX, cY
zKeys := MoveZone(pX, pY, cX, cY)
}
Else
zKeys := GetZone(pX, pY, DeadZoneX, DeadZoneY, DeadZoneRangeX, DeadZoneRangeY)
If (hKeys <> zKeys)
{
Loop, % %hKeys%0
Send, % (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
Loop, % %zKeys%0
Send, % (zKeys = "DeadZone") ? "" : "{" %zKeys%%A_Index% " down}"
hKeys := zKeys
}
return
GetZone(X, Y, DX, DY, RX, RY)
{
If (Y < (DY - RY))
Zone .= "Up"
If (Y > (DY + RY))
Zone .= "Down"
If (X < (DX - RX))
Zone .= "Left"
If (X > (DX + RX))
Zone .= "Right"
return Zone = "" ? "DeadZone" : Zone
}
MoveZone(pX, pY, cX, cY)
{
If (cY < pY)
Zone .= "Up"
If (cY > pY)
Zone .= "Down"
If (cX < pX)
Zone .= "Left"
If (cX > pX)
Zone .= "Right"
return Zone = "" ? "DeadZone" : Zone
}
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться