Disabling copy paste (including right click) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Disabling copy paste (including right click)

22 Aug 2019, 12:42

I was working on a software which required protection from copying what was inside edit boxes.

Therefore I disabled CTRL+C while the ahk window is active.
I also disabled the right click while the ahk window is active.

There is a small problem though. Someone can activate another window, say for example notepad with its window resized, and then immediately rightclick my edit box on ahk and then it would work, because at the time of the right click, the ahk was inactive.

Is there an efficient way to solve this without blocking right click on other software which are not mine?
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: Disabling copy paste (including right click)

22 Aug 2019, 13:17

Are you using "#If WinActive()" or are you using "#IfWinActive" - there is a difference and the "#If" might be lagging while it is evaluating the expression, "#IfWinActive" would be preferred. Also post code (how you disabled the mouse/^c) :)
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Disabling copy paste (including right click)  Topic is solved

22 Aug 2019, 13:26

Code: Select all

#Persistent
OnClipboardChange("ClipChanged")
return

ClipChanged(Type) {
    If WinActive("the ahk window") || MouseIsOver("the ahk window")	
		clipboard := ""
}

MouseIsOver(WinTitle){
	MouseGetPos,,, Window
	return WinExist(WinTitle . " ahk_id " . Window)
}
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Disabling copy paste (including right click)

22 Aug 2019, 13:49

I think you could use dllcall to OpenClipboard and CloseClipboard when your window becomes active or loses focus respectively to prevent the clipboard from being accessed and getting data written to regardless of using Ctrl+C or the context menu. Not sure if it would hang the script until its attempt times out.
User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Re: Disabling copy paste (including right click)

23 Aug 2019, 02:24

Thanks GEV, ingenious and works like a charm!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, Google [Bot], Spawnova and 125 guests