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?
Disabling copy paste (including right click) Topic is solved
Re: Disabling copy paste (including right click)
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)
Re: Disabling copy paste (including right click) Topic is solved
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)
}
Re: Disabling copy paste (including right click)
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.
Re: Disabling copy paste (including right click)
Thanks GEV, ingenious and works like a charm!