Code: Select all
^c::
Clipboard=
Send ^c
clipwait, 2, 1
if ErrorLevel=0
{
ToolTip %Clipboard%
sleep 400
tooltip
}
else
{
msgbox 0, NOTHING WAS COPIED, NOTHING WAS COPIED, 1
SoundBeep 100, 1000
ExitApp
}
return
Code: Select all
^c::
Clipboard=
Send ^c
clipwait, 2, 1
if ErrorLevel=0
{
ToolTip %Clipboard%
sleep 400
tooltip
}
else
{
msgbox 0, NOTHING WAS COPIED, NOTHING WAS COPIED, 1
SoundBeep 100, 1000
ExitApp
}
return
Thank you. I had included the Send ^C command in the code because the ^C:: hotkey disables the C key on the clipboard.I'm not sure why you would need a script to copy text to the clipboard, but when you want to send the same key as the hotkey, precede the hotkey with $.
Code: Select all
OnClipboardChange("clipchanged")
return
clipchanged() {
ToolTip %Clipboard%
sleep 400
tooltip
}
Code: Select all
Gosub, Test
Return
Test:
Return
Second: if the script persists without the use of #Persistent, then you don't need it!A script is persistent if any of the following conditions are true:
At least one hotkey or hotstring has been defined in the script or created by the Hotkey command or Hotstring function, even if it is not enabled.
The keyboard hook or mouse hook is installed.
The script contains any use of Gui, even if it has not been called.
The script contains any use of OnMessage, or has called it dynamically or retrieved a reference with Func.
The Input command has been called.
The #Persistent directive is present anywhere in the script.
Code: Select all
OnClipboardChange("clipchanged")
return
clipchanged() {
ToolTip %Clipboard%
sleep 400
tooltip
}
Code: Select all
OnClipboardChange("clipchanged")
return
clipchanged() {
ToolTip %Clipboard%
sleep 400
tooltip
}
Escape::
SoundBeep 100, 1000
ExitApp
return
Thank you for the explanations. Especially because English is not my native language, I did not know that the term “code” is uncountable when it is used in the context of programming. So I guess that an excerpt from a written program can be referred to as “a piece of code” or “a segment of code.”mikeyww wrote: ↑15 May 2021, 07:59Good question! I find that people on the forum sometimes do use the terms differently, and probably not correctly (i.e., according to established and accepted usage) in many instances. I will give you my take on it. Others can chime in if they disagree.
Code is a general term to refer to anything that you write in a programming language. It's code rather than a code, like stuff is stuff, rather than a stuff.
A script is all of the code in your file, together. It's the whole thing.
A routine or subroutine is typically one section that has a label, such as a hotkey label, hotstring label, or other label followed by ":". The term routine could also be used more generally, such as to refer to a loop or other section of code. Subroutine is an established term from other languages based on how sections might be called with a Gosub or Call sort of command. The notion of a subroutine is that it is a labeled block of code that can be executed, after which the script is returned to its previous sequence of commands.
Function is also frequently misused as a term. A function is something specific in the syntax, as described in the documentation. It is perhaps a special kind of subroutine that accepts parameters and can return a value or object. AHK has many built-in functions. You can also create your own in any script. The notion of function, as in mathematics, is that you have inputs, and you have an output. The output is a function of the input, and that is why it is called a function.
I believe that this description is consistent with the AHK documentation.
Macro is another term seen in the documentation.A script is simply a plain text file with the .ahk filename extension containing instructions for the program, like a configuration file, but much more powerful.
This is perhaps synonymous with "hotkey or hotstring subroutine", because "macro" has especially been used more broadly & historically, to refer to multi-command subroutines that are triggered by a keyboard sequence of some kind.A macro is a series of scripted actions that is "played" upon demand.
Code: Select all
MsgBox "this script will show a tooltip everytime the clipboard is modified, it will let you know if contents are copied or cutted"
#Persistent
OnClipboardChange("funcClipboardChange")
return
funcClipboardChange() {
sizeClipboard:=StrLen(Clipboard)
if (GetKeyState("Ctrl", "C"))
ToolTip COPIED `n size: %sizeClipboard% chars approx `n contents: %Clipboard%
else if (GetKeyState("Ctrl", "X"))
ToolTip ---SCISSORED CUTTED--- `n size: %sizeClipboard% chars approx `n contents: %Clipboard%
else
ToolTip captured `n size: %sizeClipboard% chars approx `n contents: %Clipboard%
Sleep 2000 ;wait 2 seconds
ToolTip ; destroy tooltip.
}
Code: Select all
#Requires AutoHotkey v1.1.33
~^c::tip("Copied")
~^x::tip("Cut")
tip(str) {
ToolTip % str
SetTimer tipOff, -2000
}
tipOff() {
ToolTip
}
Users browsing this forum: AlFlo and 142 guests