Page 1 of 1

Copy + Paste on Right click context menu

Posted: 05 Aug 2019, 08:32
by Vh_
I am making a right click context menu and want to include copy and paste like the standard windows context menu has. While the below code works, the paste is not instant like windows menu.

Notice I activate notepad before sending the keystrokes to copy or paste. Window menu does not steal focus from the program you right click on.

Does anyone know how to add in a proper copy and paste to a context menu?

Thanks in advance! :)
Vh_

Code: Select all

#SingleInstance,Force

TrayTip, Context Menu, Script is Active., 5, 1
Menu, Tray, Add, Copy
Menu, Tray, Add, Paste
Menu, Tray, NoStandard ;removes default options
Menu, Tray, Add,  ;creates a seperator
Menu, Tray, Add, Exit
return


#IfWinActive, Untitled - Notepad
RButton::
Menu, Tray, Show  ; right mouse and windows
return

Copy:
WinActivate, Untitled - Notepad
Send, {AppsKey}c
Return

Paste:
WinActivate, Untitled - Notepad
;ControlFocus, %WhatField%, MyProgram
Send, {AppsKey}p
Return


Exit:
ExitApp

Re: Copy + Paste on Right click context menu

Posted: 06 Aug 2019, 10:00
by Sir Teddy the First
Hi,
although I'm not completely satisfied with my solution, it works - and even better, it works in any program.

Code: Select all

#SingleInstance,Force

TrayTip, Context Menu, Script is Active., 5, 1
Menu, Tray, Add, Copy
Menu, Tray, Add, Paste
Menu, Tray, NoStandard ;removes default options
Menu, Tray, Add,  ;creates a seperator
Menu, Tray, Add, Exit
return


RButton::
Menu, Tray, Show  ; right mouse and windows
return

Copy:
Send {LWin}
Sleep 75
Send {LWin}
Send ^c
Return

Paste:
Send {LWin}
Sleep 75
Send {LWin}
Send ^v
Return


Exit:
ExitApp

Re: Copy + Paste on Right click context menu

Posted: 06 Aug 2019, 10:10
by Sir Teddy the First
Hi again,
I found a better solution.
This one will keep track of the active window on right-click and willl activate it again after the user clicks on a menu-entry.

Just replace the above with this:

Code: Select all

RButton::
WinGetTitle, WindowCache, A
Menu, Tray, Show
return

Copy:
WinActivate, %WindowCache%
Send ^c
Return

Paste:
WinActivate, %WindowCache%
Send ^v
Return
Hope I could help!

Re: Copy + Paste on Right click context menu

Posted: 06 Aug 2019, 20:48
by Vh_
Sir Teddy the First wrote:
06 Aug 2019, 10:10
Hi again,
I found a better solution.
This one will keep track of the active window on right-click and willl activate it again after the user clicks on a menu-entry.

Just replace the above with this:

Code: Select all

RButton::
WinGetTitle, WindowCache, A
Menu, Tray, Show
return

Copy:
WinActivate, %WindowCache%
Send ^c
Return

Paste:
WinActivate, %WindowCache%
Send ^v
Return
Hope I could help!
Thanks for the reply! I did try something similar. It works, that's the main goal! I'd just love to have it instant like windows, but it's a luxury to have our custom menu as it is, I suppose. :) :) Thanks again!

Re: Copy + Paste on Right click context menu

Posted: 07 Aug 2019, 03:34
by Sir Teddy the First
Vh_ wrote:
06 Aug 2019, 20:48
I'd just love to have it instant like windows ...
I do not quite understand that. When I run my code it is instant, there is absolutely no delay or anything.

What exactly does it do when you say "it is not instant"? :wtf:

Re: Copy + Paste on Right click context menu

Posted: 22 Aug 2019, 07:32
by Vh_
Sir Teddy the First wrote:
07 Aug 2019, 03:34
Vh_ wrote:
06 Aug 2019, 20:48
I'd just love to have it instant like windows ...
I do not quite understand that. When I run my code it is instant, there is absolutely no delay or anything.

What exactly does it do when you say "it is not instant"? :wtf:
Hey! I ended up removing the delay with ControlGetFocus and ControlFocus. It was WinActivate that made it have such a lag. :)

Thanks for all your help! :)