Тема: AHK: Закрыть форму меню автоматически через пару секунд
Здравствуйте.
Пробую написать скрипт наподобие функционала программы PopClip (Mac OX).
При выделение текста автоматически возле курсора появляется меню с кнопками Copy, Paste, Search in Google и т.д.
Подскажите как сделать, чтоб меню само исчезало через короткое время если по нему не кликнули
и работа дальше продолжалась?
~LButton::
TimeButtonDown = %A_TickCount%
; Wait for it to be released
Loop
{
Sleep 10
GetKeyState, LButtonState, LButton, P
if LButtonState = U ; Button has been released.
break
elapsed = %A_TickCount%
elapsed -= %TimeButtonDown%
if elapsed > 200 ; Button was held down too long, so assume it's not a double-click.
{
MouseGetPos x0, y0 ; save start mouse position
Loop
{
Sleep 20 ; yield time to others
GetKeyState keystate, LButton
IfEqual keystate, U, {
MouseGetPos x, y ; position when button released
break
}
}
if (x-x0 > 5 or x-x0 < -5 or y-y0 > 5 or y-y0 < -5)
{ ; mouse has moved
menu_context := false
{
if ( ! menu_context )
{
menu, context, add, Kopieren
menu, context, add, Einf¸gen
menu, context, add, Google
menu_context := true
}
Menu, context, Show
}
return
Kopieren:
Send, ^{vk43} ;Send, ^c ; Copy.
clipboard = %clipboard% ; Convert the cliboard contents to plain text.
return
Google:
MsgBox, You selected "%A_ThisMenuItem%" in menu "%A_ThisMenu%".
return
Einf¸gen:
Send, ^{vk56} ;send, ^v ; Paste
return
} ; mouse has moved
return
}
}
; Otherwise, button was released quickly enough. Wait to see if it's a double-click:
TimeButtonUp = %A_TickCount%
Loop
{
Sleep 10
GetKeyState, LButtonState, LButton, P
if LButtonState = D ; Button has been pressed down again.
break
elapsed = %A_TickCount%
elapsed -= %TimeButtonUp%
if elapsed > 350 ; No click has occurred within the allowed time, so assume it's not a double-click.
{
;MouseClick, Left
return
}
}
; Since above didn't return, it's a double-click:
Sleep, 100
;Send, ^c
return



