I need an AHK code to implement the function that
when holding the left mouse, select the texts to be copied, and then click the right mouse, the selected texts are copied.
And then when I double-click the right mouse, the copied texts are pasted. (No right-click pop-up window will appear when double right click).
Note: when this action happens on a file, the file is copied, and can be pasted when double right click.
Any guru help me with this script is so kind cause I'm looking for this script for a long time.
Any Guru help me with mouse copy and paste
Re: Any Guru help me with mouse copy and paste
So for the copy function, please clarify if I have this wrong. But you want it so that if LButton (left mouse; see KeyList) is down, and you press RButton as well, it should act as a copy? (It would be tough to add in detecting that you have highlighted text, before asking for a copy. But if no text is highlighted, then the copy should fail.)
So that first bit can be done using the #If directive in combination with GetKeyState() function which checks if LButton is physically pressed. Then, use RButton as a hotkey to do Send ^c as a shortcut for copying.
(Do note that to remove the effects of #If and make any hotkey functional at all times, just use a plain #If with no conditions - any hotkeys listed below it will work normally. You'd probably want this for the next step: )
The next action you wanted is to make a double right click act as paste, but to suppress the native action of a right click. It's tricky to balance this if you ever want right click to act normally. But there are commands like KeyWait that can wait for you to release the key, then wait for you to press the key again within a time limit, and then take actions depending if you did that or not. You can use the If expression (Different from #If) to decide if the hotkey should use Send ^v depending on the results of KeyWait, or if it should send a normal RButton key stroke (optional) by Send {RButton} or Click right. The way to use KeyWait's time out and if statements is like this:
(; signals the start of a comment)
Give it a whirl yourself and see what you can come up with. I don't expect you to get it right on the first try, but a number of people here would be able to help walk you through it. I also would not be surprised that even if we get the functionality to do what you ask, you might change your mind or ask for ideas on how it can be improved to better integrate into your workflow.
So that first bit can be done using the #If directive in combination with GetKeyState() function which checks if LButton is physically pressed. Then, use RButton as a hotkey to do Send ^c as a shortcut for copying.
(Do note that to remove the effects of #If and make any hotkey functional at all times, just use a plain #If with no conditions - any hotkeys listed below it will work normally. You'd probably want this for the next step: )
The next action you wanted is to make a double right click act as paste, but to suppress the native action of a right click. It's tricky to balance this if you ever want right click to act normally. But there are commands like KeyWait that can wait for you to release the key, then wait for you to press the key again within a time limit, and then take actions depending if you did that or not. You can use the If expression (Different from #If) to decide if the hotkey should use Send ^v depending on the results of KeyWait, or if it should send a normal RButton key stroke (optional) by Send {RButton} or Click right. The way to use KeyWait's time out and if statements is like this:
(; signals the start of a comment)
Code: Select all
KeyWait, Space, D T1 ; waits 1 second for you to press Space.
If ErrorLevel ; errorlevel is true when the time limit is reached in KeyWait
MsgBox Space was not pressed
else
MsgBox Space was pressed within one second
return
- Blackholyman
- Posts: 1293
- Joined: 29 Sep 2013, 22:57
- Location: Denmark
- Contact:
Re: Any Guru help me with mouse copy and paste
What @Exaskryz said
Spoiler
Courses on AutoHotkey
My Autohotkey Blog
Re: Any Guru help me with mouse copy and paste
Please check the following 2 scripts. These 2 scripts can run properly and implement the function alone, but when I run them both, the 2nd script just doesn't work. I think there are conflicts in between.
The 1st script:
The 2nd script:
It will be amazing if you could find the conflict and make them both work properly. Another thing is that, the 2nd script will flash the right-click pop up window, though the function is good. It will be so nice if you could eliminate the pop-up window.
The 1st script:
Code: Select all
#NoTrayIcon
#IfWinNotActive ahk_class ConsoleWindowClass
bAllowOverride := False
~LButton::
GetKeyState, keystate, RButton
If (keystate = "D")
{
SendInput {RButton Up}
SendInput {Escape}
SendInput ^v
bAllowOverride := True
}
Return
RButton::
GetKeyState, keystate, LButton
If (keystate = "D")
{
SendInput {LButton Up}
SendInput ^c
bAllowOverride := True
Return
}
SendInput {RButton Down}
Return
RButton Up::
GetKeyState, keystate, LButton
If (keystate = "D")
{
Return
}
If (bAllowOverride)
{
bAllowOverride := False
Return
}
SendInput {RButton Up}
Return
Code: Select all
;Double Right Click to paste
~RButton::
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500)
{
Sleep 200 ; wait for right-click menu, fine tune for your PC
Send {Esc} ; close it
Send ^v ; or your double-right-click action here
}
Return
Re: Any Guru help me with mouse copy and paste
You have two RButton hotkeys.
One approach is to merge these hotkeys. You can use else to give a new set of instructions to the first RButton hotkey for when the LButton is not held down. However, it may be tricky to combine your logic with the RButton Up hotkey, because that would change the A_PriorHotkey value. Though, you could use If (A_PriorHotkey = "RButton Up" and A_TimeSincePriorHotkey < 500).
Additionally, the reason in the second code you see the pop up is because of the ~ modifier. It's a pass-through. It does not suppress the native action of the RButton, which is to bring up the menu. AHK cannot read the future. It cannot know your intent. You'd have to get rid of the pass-through modifier. The easiest way to do it is just put a delay on the native action, such that if it turns out you only press RButton once in 500 ms, it should perform an artificial right click/RButton press - that's why I used a KeyWait approach, and Black used a Timer approach. (In Black's timer, there is also logic that I hadn't explained thoroughly - it will attempt to copy data, and if it fails, it assumes you had nothing selected, in which case it should act like a normal RButton press. It does not check that you actually pressed LButton or were still holding it prior to pressing RButton.)
One approach is to merge these hotkeys. You can use else to give a new set of instructions to the first RButton hotkey for when the LButton is not held down. However, it may be tricky to combine your logic with the RButton Up hotkey, because that would change the A_PriorHotkey value. Though, you could use If (A_PriorHotkey = "RButton Up" and A_TimeSincePriorHotkey < 500).
Additionally, the reason in the second code you see the pop up is because of the ~ modifier. It's a pass-through. It does not suppress the native action of the RButton, which is to bring up the menu. AHK cannot read the future. It cannot know your intent. You'd have to get rid of the pass-through modifier. The easiest way to do it is just put a delay on the native action, such that if it turns out you only press RButton once in 500 ms, it should perform an artificial right click/RButton press - that's why I used a KeyWait approach, and Black used a Timer approach. (In Black's timer, there is also logic that I hadn't explained thoroughly - it will attempt to copy data, and if it fails, it assumes you had nothing selected, in which case it should act like a normal RButton press. It does not check that you actually pressed LButton or were still holding it prior to pressing RButton.)
Re: Any Guru help me with mouse copy and paste
Hi~Thank you very much for the explanation. Great thanks to GEV, I have got the scripts which implement all the functions I need. Here it is.
The only problem is that it still shows up pop-up window when double right click. It would be very kind if you cloud lend a hand and make it perfect.
Mod edit: Added code tags.
Code: Select all
#NoTrayIcon
; Double Right Click to paste:
~RButton::
If (A_PriorHotKey = "~RButton Up" and A_TimeSincePriorHotkey < 500)
{
CloseContextMenu := true
KeyWait, RButton, L
Sleep, 100
Send ^v ; or your double-right-click action here
}
Return
~RButton Up::
CloseContextMenu := false
Return
~LButton & RButton::
CloseContextMenu := true
KeyWait, RButton, L
KeyWait, LButton, L
Send ^c
Return
~RButton & LButton::
CloseContextMenu := true
KeyWait, LButton, L
KeyWait, RButton, L
Send ^v
Return
#If (CloseContextMenu)
RButton Up::
CloseContextMenu := false
Sleep, 30 ; or more
Send {Escape}
Return
#If
Mod edit: Added code tags.
Who is online
Users browsing this forum: No registered users and 213 guests