Difference between "IfWinActive" and "If WinActive()" - autohotkey

Can anybody explain the difference between IfWinActive and If WinActive()? I'm really wondering, but Google and official AutoHotkey docs says nothing about.

If IfWinActive evaluates to True, the next line of code (or brace-bracketed code block) is performed, or if False, it is skipped. All it does is evaluate to True or False.
The function WinActive() returns the Unique ID (HWND) of the active window if it matches the specified criteria. If it does not, the function returns 0. Since all non-zero numbers are seen as "true", the statement If WinActive("WinTitle") is true whenever "WinTitle" is active, and then acts just like IfWinActive WinTitle. Note the quotes in the function, but not the directive.

Related

Can anyone pls explain this ahk script logics/commands

Can anyone pls tell what is the purpose of two sequential commas and then 1 in the below given ahk script?
Pause:: Suspend
Pause,,1
return
If the script is suspended you can't unpause with that very same button because the hotkey is disabled.
In that case you need to use the OperateOnUnderlyingThread in the Pause command parameters:
Pause,,1 makes a single button (in this case the button Pause or Break) work as both pause and unpause. It allows the Pause command to run a second time (i.e. to unpause).
Pause::
Suspend ; disables or enables all or selected hotkeys and hotstrings.
Pause,,1
return
It indicates that the first parameter is blank.
https://lexikos.github.io/v1/docs/Language.htm#commands
The comma separating the command name from its parameters is optional, except in the following cases:
When it's necessary to prevent the line from being interpreted as a legacy assignment or assignment expression.
MsgBox, := This would be an assignment without the comma.
When the first parameter is blank.
MsgBox,, Second, Third
From https://www.autohotkey.com/docs/commands/Pause.htm :
Pause [, OnOffToggle, OperateOnUnderlyingThread]
OnOffToggle
If blank or omitted, it defaults to Toggle. [...]
Pause,,1 is the same as Pause,Toggle,1
I think I got the answer.
Two commas mean there is a blank value, which in ahk means 'Off'. In other words it'd be perhaps same if it were: Pause, Off, 1
And 1 means on. That means, it is equal to
Pause, Off, On
I'm only 95% sure of the above.

Eclipse breakpoint conditional skipping

I read several posts on this but I could not fix my problem which is that eclipse skips a conditional I defined on a variable.
if(currentContent=="content") {
return true;
}
Can you please advice what I should do for the conditional to trigger the breakpoint when the value of my string variable is equal "content".
You can't rely on == with Strings. Use .equals().
nitind's point about using .equals is important, but I think a bigger issue is that the breakpoint condition is evaluated BEFORE the line executes, not after. I get the feeling you want to hit the breakpoint when the resulting value of "currentContent" matches your expectations AFTER the assignment, not before.
In this case, I suggest you move your breakpoint to the executable line that comes after this line.

Autohotkey Input Times Out Because MatchList Isn't Matched

Here's my AHK script
:*:if ::
SendInput IF{Space}
Input cond, I V T5,, then
msgbox %ErrorLevel%
msgbox %cond%
if (ErrorLevel = "Match")
{
SendInput {Enter}End If{Space}'%cond%
}
Return
When I type If x = 1 then I get an ErrorLevel of 'Timeout' and a cond of 'x = 1 then'
My understanding is that when I type then it's supposed to stop the Input and set the ErrorLevel to Match.
I've tried putting it in quotes, using single letters in the MatchList, and including and end key, but none of works. The few examples I could find of using MathList look just like mine.
Input cond, I V T5 *,,% " then"
Without the asterisk option, an item in MatchList needs to be the next thing typed. So If Then would match then in the MatchList. But If anything then doesn't match then in the MatchList because it's trying to match anything then, not just then.
With the asterisk option, if anything then is matched because the next thing typed after If contained then. That causes problems if you type if heathen then because the then in heathen triggers it. The space before then should fix that, but it doesn't.
AHK help says that the MatchList respects spaces, but it doesn't seem to do that when the space is before the first (or only) item in MatchList. The two ways around that are to include a dummy word at the beginning or to use the % thingy to quote the MathList item and include the space.
See also http://ahkscript.org/boards/viewtopic.php?f=5&t=3979
I strongly recommend using RegEx powered hotstrings for this purpose:
#Include <Hotstrings>
hotstrings("if (.*?) then", "If %$1% then``nEnd If%A_SPACE%")
The definition of "T" in the AutoHotkey Help File states this:
T: Timeout (e.g. T3). The number of seconds to wait before terminating the
Input and setting ErrorLevel to the word Timeout. If the Input times out,
OutputVar will be set to whatever text the user had time to enter.
Basically, this is saying exactly what is to be expected (and what is actually happening) with your script. So, for me when I type "if x = 1 then" my "if" is immediately replaced with the caps lock IF and a space.
After 5 seconds, the first MsgBox appears with "Timeout" as the text (again, expected since ErrorLevel is set to the word "Timeout" when the "T" option is present). Once that MsgBox is dismissed, I receive the second MsgBox which (according to the help file) contains OutputVar which is what I (the user) had time to enter in before the Timeout.

Is there AndAlso equivalent for Matlab?

I need to check validity of an expression and if it was true then check 2nd exp.
It can be written in 2 if-end structures but I want to put condition in conditional breakpoint, and I think it is not possible to write 2 if in one line.
But AndAlso can solve my problem.
any idea?
If you use the shortcut AND, i.e. &&, the second statement is only evaluated if the first one was true. Thus, something like
i>1 && foo(i)==3
should do the trick.

Emacs mode 1, 2 and t (what t stands for)?

For instance, global-linum-mode 1 enables line numbers global-linum-mode 0 disables line numbers, what global-linum-mode t would do? and I've seen another parameter: nil. What do they do?
t and nil in boolean context are the (Emacs) Lisp truth values. nil is false. Any non-nil value is considered to be true, but t is customarily used. Source.
As for global-linum-mode, any non-negative parameter will enable it, including t, "foo",... etcetera.
For such questions it is very useful to play in the scratch buffer with elisp: type your expression there and press C-j.
t is true, nil is false.