AutoHotKey :: Function Key not working properly - windows

Solved
Also check comments
I wrote a command in a script to emulate the function keys, to rename files easily(Windows F2 key helps renaming files.)
The script is pretty basic(I use multiple hotkey scripts instead of pasting all in one for more flexibility):
#l:: ; Windows Key + L
F2
It just doesn't seem to work on the normal folders I want to change names of. Any advice is appreciated.

You can either use:
#l::F2 ;for a simple one-to-one remap
or, alternatively:
#l::
Send {F2}
;insert more code here for a multiline command
return

Related

F1 as an arguement to shell?

Im just trying to understand this code Im working with. I can find sources for single digits # https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/shell-function
Though I dont see anything there or online
Shell ("rundll32.exe """ & App.Path & "\SomeFile.dll"",F1")
'This is from the linked source earlier Shell (pathname, windows style)
It may also be using rundll32.exe as for adding the optional F1 arguement
https://support.microsoft.com/en-us/help/164787/info-windows-rundll-and-rundll32-interface
Though I dont see any docs on F1 there either
I could be misreading the quotes. But im pretty sure its passing in the path like so. "rundll32.exe\App.Path\somefile.dll" and the second argument is F1
If someone could either tell me I'm wrong on my quotes and F1 is an argument that would be enough. If it isn't an its a windows style. What it means would be great. Thank you.
As written, with the quote marks as they are, F1 is not an argument to Shell. It's an argument to rundll32 and is the entry point into SomeFile.dll. This is explained in the link you referenced to rundll32.

Paste from a file one line (or section) at a time

I am a teacher using Windows and would like to be able to paste short program snippets one after another from a file of examples I have into whatever programming environment I am teaching (e.g. the python IDLE shell or editor). During the lecture I would have IDLE open and then use Ctrl-v to paste line 1 from the file into IDLE, execute & discuss it, then use Ctrl-v to paste line 2 from the file into IDLE, execute & discuss it, then use Ctrl-V to get line 3 into IDLE, and so on ...
I suspect there is some way to do this with a clipboard manager, but haven't found it online.
Being able to paste sections of code instead of just single lines would be really useful as well. The sections of code in the file could be separated by a blank line or some kind of text string indicator.
Having this functionality would allow me to have all my examples ready in a file and then during the lecture have quick access to all the examples one at a time by using Ctrl-v.
The following AutoHotKey script will paste lines from the clipboard, one line at a time, when you press Win+Ctrl+V (on Windows).
If you haven't used AutoHotKey, I highly recommend it.
#^v::
{
originalClipboard := Clipboard
StringSplit, ClipLines, originalClipboard, `n`r
size := StrLen(ClipLines1) + 3
Clipboard = %ClipLines1%
Send ^v`n
Clipboard := SubStr(originalClipboard, size)
return
}
Caveats:
It may not robustly handle line endings--it only works for two-character \r\n endings (the Windows standard). This should be most if not all real-world usages.
AutoHotKey seems to be only for Windows.
After you paste a line, that line is removed from the clipboard so that you are ready for the next one.
It always pastes a whole line at a time, even if the source was a partial line.
When you run out of clipboard lines, it pastes blank lines till you realize it.
It adds a new line by sending a newline. Not sure if this works in all text editors, but it worked in Notepad and a few others I tried.
There may be other nuances that it doesn't handle well.
Unfortunately, I cannot comment, but the great solution by #Patrick only works for me when I add a sleep command - otherwise, the clipboard content gets overwritten before the line is pasted. So if you run into a similar issue, the following version might do it:
#^v::
{
originalClipboard := Clipboard
StringSplit, ClipLines, originalClipboard, `n`r
size := StrLen(ClipLines1) + 3
Clipboard = %ClipLines1%
Send ^v`n
sleep, 500 ;
Clipboard := SubStr(originalClipboard, size)
return
}
Install the MultiLineRun.py script from the IdleX extensions for IDLE (or the whole of IdleX). Idlex is available here: http://idlex.sourceforge.net/.
If you want to automate it:
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("Python 2.7.9 Shell")
# or the title of your idle shell window
for line in source.readlines():
# open your source file of examples
# better parse it into groups of commands
# and work each group in a batch
line= line.replace("(","{(}") # sendkeys escape
line= line.replace(")","{)}")
shell.SendKeys(line)
shell.SendKeys("{ENTER}") # for good measure.
"""SendKeys sends a string to the active window.
You can automate reading lines in batches linked to a button press etc
put in delays, copy per char etc
Go to town and make it a mini slide show!
"""

automate creating sql statements using scripting tool

I often have a task a bit like this: insert a large number of users onto to the users table with similar properties. Not always that simple, but in general, list of strings -> list of corresponding sql statements.
my usual solution is this with the list of usernames in excel use a formula to generate a load of insert statements
=concatenate("insert into users values(username .......'",A1,"'.....
and then I fill down the formula to get all the insert rows.
This works but sometimes the statement is long, sometimes including a few different steps for each, and cramming it all into an excel formula and getting all the wrapping quotes right is a pain.
I'm wondering if there is a better way. What I really want is to be able to have a template file template txt:
insert into users
([username],
[company] ...
)
values('<template tag1>...
and then using some magic command line tool, to simply be able to type something like
command_line> make_big_file_using_template template.txt /values [username1 username2]
/output: bigfile.txt
and this gives me a big file with the template repeated for each username value with the tag replaced with the username.
So does such a command exist, or are my expectations of command line tools too high? Any freely available windows tool will do. I could whip up a c# program to do this in not too much time but I feel like there must be an easy to use tool out there already.
This is trivial using a Powershell script. PS allows inline variables in strings, so you could do something like:
$Tag1 = 'blah'
$Tag2 = 'foo'
$SQLHS = #"
INSERT INTO users
([username],
[company],...)
VALUES
('$tag1', '$tag2'...)
"#
set-content 'C:\Mynewfile.txt' -value $SQLHS
The #"...."# is a here-string, which makes it very easy to write readable code without escaping quotes and such.
The above could be very easily modified to accept parameters for the various tags and another for the output file, or to run for a set of values located in another .txt or .csv file as inputs.
EDIT:
To modify it to accept parameters, you can just add a param() block at top:
param($outfile, $tab1, $tab2, $tab3)
Then use those $variables in your script:
set-content "$outfile" -value $SQLHS

VIM prompting for a variable when running a macro?

I find I waste a lot of time closing and reopening sets of files so I'd like to improve my VIM macro for loading and saving the session to support multiple sessions.
I'd like for it to prompt for a string value, so that I could press my shortcut, then type in for example "foo", and have my macro save the session to .foo (so I also need to do basic string concat on it). Then I'd do the same for the load macro and manage sessions by theme (using MVC framework you tend to have a lot of files to work with).
" Control-S to save and Shift F5 to load
set sessionoptions=tabpages,winpos
map <S-F5> :source ~/.vim/.session<cr>
map <c-s> :mksession! ~/.vim/.session<cr>\| :echo "Session saved."<CR>
I have very little experience of VIM scripting. Is it possible to do this in a one liner, or perhaps a small function?
Thank you.
map <s-f5> :execute "source ".input("session name: ", "~/.vim/session.", "file")<cr>
Enter "foo" to load "session.foo".
Instead, you can also do:
map <s-f5> :source ~/.vim/session.
Note there isn't a <cr>, so you complete the command yourself and press enter — identical typing as above, even down to filename completion.
However, I'd look at calling a function or something else entirely at about this point.
Here's the snippet I have now, in case someone needs something similar (no need to vote). It saves sessions under .session.xyz which are also excluded from my Git project. I like to store them in the Git project folder so they are saved with backups.
I like confirmation echo as well because when you press enter after saving the session otherwise you can't see that anything happened. It's just for feedback.
map <S-F5> :execute "source ".input("Load session: ", "~/Some/Project/.session.", "file")<cr>
map <c-s> :execute "mksession! ".input("Save session: ", "~/Some/Project/.session.", "file")\| :echo "Session saved."<CR>
The file completion makes this very handy, thank you!

Is there a shortcut to swap/reorder parameters in visual studio IDE?

I have a common issue when working with code in the IDE:
string.Concat("foo", "bar");
and I need to change it to:
string.Concat("bar", "foo");
Often I have several of these that need to be swapped at once. I would like to avoid all the typing. Is there a way to automate this? Either a shortcut or some sort of macro would be great if I knew where to start.
Edit: changed to string.Concat to show that you can't always modify the method signature. I am only looking to change the order of the params in the method call, and nothing else.
<Ctrl> + <Shift> + <t> will transpose two words, so it would work in your case. Unfortunately I don't see this working (without multiple presses) for functions with larger parameter lists...
I had a lot of code with this function:
SetInt(comboBox1.Value + 1, "paramName", ...
SetInt(comboBoxOther.Value, "paramName", ...
And I needed to swap only the first two parameters;
I ended up using some text editor with regular expression management (like Scite), and using this one saved me hours:
Find: SetInt(\([.a-z0-9]+[ + 1]*\), \("[a-z0-9]+"\)
Replace: SetInt(\2, \1

Resources