Why would a white space change the meaning of a sentence in auto hotkey? - autohotkey

Recently I noticed a problem that it seems when I call a function with a white space included, the function call won't work correctly.Example:
while true
{
tooltip, % getkeystate ("lbutton","p")
;tooltip, % getkeystate("lbutton","p")
}
return
the code commented works correctly showing 1 or 0 ,but the former one always shows "lbutton", which confused me a lot, I wonder:
1.What causes the difference?
2.What is the syntax of the former one?Why would it return the key name?
3.When would a white space affect the meaning of a sentence?

It is because in the first one, the tooltip evaluates the expression which in this case starts with the empty variable getkeystate and then returns the quoted string lbutton so that is what the tootltip shows.
The second one evaluates a function getkeystate(parameters) to put in the tooltip.

Related

How to add a small straight line (I mean like this: a̅ b̅ X̅) onto a character inside a string?

I want to add small straight line onto some desired characters/numbers inside a string inside textview. I couldn't find a solution. Maybe using NSMutableAttributedString. Meanwhile, I mean doing this programmatically. There is strikethrough style, but not overstrike style. Or maybe adding the letters "a" and "_" with different .baseline values. But how to add both characters onto each other then?
Is it possible?
EDIT: Due to make a try for the helpful answers below, I think to make the line at a spesific height is needed. "A\u{0305}" makes the up line very close to the character, as if it sticks. Is there a way to make it at specific height? For example, if we assume that all the keyboard-inputted characters are written inside every single boxes, the ceiling side of these boxes could be lined?
So this (note: see edit below) appears to be an "a tilde ogonek" (it's Lithuanian).
You can write it for instance as follows using these two Unicode characters:
let atildeogonek = "\u{0105}\u{0303}"
let title = "How to add a small straight line (I mean like this: \(atildeogonek)) onto a character inside a string?"
The first character is the a with an ogonek, the second one is the tilde.
EDIT: The initial question specifically asked about the character ą̃ ("a tilde ogonek") in the title, and I used this code to demonstrate how to use Unicode characters in a Swift string. After posting this answer, the question was edited to be more general about "a line above a character".
Programmatically, you could use a function like this:
func overline(character: Character) -> Character? {
return "\(character)\u{0305}".first
}
That will take a character as input and return a new character (glyph) that has had the Unicode combining overline character added to it. It will return nil if adding the combining overline character fails.
The code print(overline(character:"A")!), for example, returns "A̅"
Or, if you want to add an overline to every character in a string, you could use a function like this:
func overline(characters: String) -> [Character?] {
return Array(characters).map { return "\($0)\u{0305}".first
}
}
(I'm not sure if there are any characters for which the above will fail, so I'm not sure if force-unwrapping the result is safe. Thus I left the result of both functions to be optional Character/Array of Character.)
You can easily find the unicodes of ā or ą̃ by using the xcode's own Character Viewer. Just follow the following steps :
hit : Control + Command + SpaceBar
If you get a compact one like this, click the upper right corner icon to expand it.
When expanded, Click the settings gear in the corner . Select customize list.
select Enclosed Characters
Go down to the bottom and open Code tables then add Unicode.
Now, just search for your required Character and you can check its unicode value. here i am searching ā
to print unicode's value :
print("\u{0101}")

IF statement with Condtional Formating Crystal

I want to do an IF statement that has 2 outcomes:
I want it to say a word
I want it to be a color
For example:
IF {Command.Check in/Appt} < 0
THEN "Early" AND crGreen
ELSE "LATE" AND crRed
In the above example the AND does not work.
A Boolean is required here.
So I just need to find a way to have those 2 outcomes
Short of using shared variables, you can't do that. One formula, one output.
But there's nothing saying you can't have two nearly identical formulas, (One for Early/Late, one for Red/Green) - And in Crystal, that's the best way to do it. (Glad to see you figured that out on your own.)
The reason the AND keyword was giving you trouble is because AND is a Boolean operator. Whenever you use AND, you're basically using this function:
Take booleans FOO and BAR as input.
I return true if, and only if, FOO and BAR are both true.
If at least one of them is false, I return false.
So the AND keyword was expecting two booleans for input. Instead you gave it a string and a color. Ask a machine if the color Red is equal to true, it's going to complain.
Ok, while I didn't find a solution by adding it in the formula, I did find a solution.
For those who have the same problem, just keep the IF statement:
IF {Command.Check in/Appt} < 0
THEN "Early"
ELSE "LATE"
Then save and go to Format > Highlight Expert to enter the formatting conditions you like.
In the above case, I did:
New > Value of: this field is equal to "Early" Font color Green
New > Value of: this field is equal to "Late" Font color Red

How to make participant input appear on screen and be wrapped (Psychtoolbox)

I’m trying to create a rectangle box on screen in PTB wherein the participant can type text that is wrapped inside this box. So I would like to get the string input to be drawn on screen while typing in a rectangular box where the text input is wrapped to avoid it continuing outside the border of this box. I have been searching for a while now and haven’t found anything that works or anyone who did this before. I assume I might be overlooking something very simple.
I have tried using:
% Textbox
Screen('FrameRect',window, white, [300 300 1600 600],4);
message = [‘Your comments: ‘];
replySubj = Ask(window, message, white, black, 'GetChar',[300 225 1600 600]);
The response input is nicely drawn on screen while typing, but only on one line that is not wrapped when I reach the side of the box, or even my screen. Is their a way to wrap the text (e.g. by integrating WrapString.m) so it stays inside a specified rectangle on screen, and continues to a new line if the text is too long for one line?
Any help is very much appreciated.
Looking at the GetEchoString function, it does the following upon each character strike (to the best of my understanding of how the display is managed):
if it is Ctrl-C, Enter, or Return: exit;
if it is Backspace, issue command to re-draw the previous full string (prompt + user input) with the same colour as the background to erase it ; then remove the last character from the stored full string;
else append the character to the stored full string.
Then issue the command to draw the resulting updated full string in the specified colour, and finally update the screen following the previous commands, with the option dontclearset to 1 (incremental drawing, cf. Screen('Flip', windowPtr, 0, 1) call).
To add wrapping capabilities, we can thus modify GetEchoString as follows:
comment out the re-drawing commands when Backspace is hit, simply updating the stored string (see below);
add a call to WrapString on the updated string to wrap it;
used DrawFormattedText to issue command to display the wrapped string;
finally, call Screen('Flip', windowPtr) that is update the screen with dontclearset to 0 (default).
The relevant part of the function are now thus:
% adapted from PTB3 GetEchoString
while true
if useKbCheck
char = GetKbChar(varargin{:});
else
char = GetChar;
end
if isempty(char)
string = '';
break;
end
switch (abs(char))
case {13, 3, 10}
% ctrl-C, enter, or return
break;
case 8
% backspace
if ~isempty(string)
% Remove last character from string:
string = string(1:length(string)-1);
end
otherwise
string = [string, char];
end
output = [msg, ' ', string];
output=WrapString(output,maxNumChar);
DrawFormattedText(windowPtr,output,x,y,textColor,[],0,0,vLineSpacing);
Screen('Flip',windowPtr);
end
Where maxNumChar and vLineSpacing are to be defined depending on your needs.
This will take care of the horizontal wrapping of the text, while keeping the Backspace function working. Note however that you could still overflow vertically if the whole screen is filled.

highlight expressions on netbeans

I want to know if there is a way to highlight the full content in an expression like if, while, etc.
I have to work in a code that is bad indented where expressions can cover over 1000 lines and I can't format it.
for exemple :
if ($somethingTrue) {
while ($somethingHappen) {
// 500 lines...
} }
if ($someCondition) {
}
look, it's very hard to see the end of the first if and what it cover...
Does someone know if there is a native feature or plugin on netbeans that do this job ?
Thanks !
You don't need any plugin/external jar file for achieving the same. Whichever expression you want to check the body of, just click on the opening brace after that expression and NetBeans will automatically show you the closing brace for that expression.
Basically, Netbeans shows the ending brace for a corresponding starting brace entry---for each of if-statements,loop-statements,method declarations,etc.
In the shown figure, see my if-statement starting with yellow brace(cursor blinking there), and the corresponding ending brace for the if-statement.
EDIT :-
You also can also have a brand new-code fold,just by typing fcom, and hitting (Tab) button on KeyBoard. And, then put whatever block you want inside it and done. Expand whenever you wish and collapse whenever you want.
Check the position of my mouse-pointer which shows the current block of if-statement. You can expand and collapse as per your wish. And, also you can have several of them for each of your expression-tree.

comment out an interval in matlab through command line

I have a very long script in MATLAB (1500 lines) and want to test two different settings. To do so, I need to comment out some codes in a specific interval (e.g. form line 234 to line 255).
Is there a function in MATLAB that takes the intervals and comments/uncomments them automatically?
You can just highlight your code and click on the comment button. Highlight and click on uncomment to remove comment.In windows you may also use shortcut keys cntrl+r and cntrl+t. But yeah, the if else is a better idea but takes more time in the beginning to code in the if else.
I would agree with others that putting your code into a block surrounded by if-else would probably be a better solution than what you originally asked for.
But if you want to do it, you can use the following function:
function commentout(fromline, toline)
currentDoc = matlab.desktop.editor.getActive;
currentDoc.insertTextAtPositionInLine(sprintf('%%{\n'), fromline, 0)
currentDoc.insertTextAtPositionInLine(sprintf('%%}\n'), toline+1, 0)
This will work in most recent versions of MATLAB.
To uncomment, I think you'll need to do something a bit more complex, like getting the entire text from the active document, removing the specified comment lines, then setting the entire text back again (get, modify and set the Text property of the document).