I was wondering.. How can I assign a variable / text to a key (shortcut)?
This is what I am trying to achieve:
myVar = Hello
#F11 = myVar ;myVar ("hello") is stored / bound to the shortcut: `WINDOWS+F11`.
So, whenever I press WINDOWS + F11, it should paste/write the content of myVar.
Is this even possible? If yes, can I do it with multiply keys?
This is the correct syntax:
SendMode Input
myVar := "Hello"
myOtherVar := "World"
#F10::Send, Hello world!
#F11::Send, %myVar%
#F12::Send, %myOtherVar%
You'll notice that the text is only sent when you release the WIN-key. This is intended, and is a special behavior for the WIN-modifier. You can read more about it here.
Related
The problem that I'm facing is that I have an entire column that has text separated by _ that contains pixel size that I want to be able to extract but currently can't. For example:
A
Example_Number_320x50_fifty_five
Example_Number_One_300x250_hundred
Example_Number_two_fifty_728x49
I have tried using Substitute function to grab the numbers which works but only grabs the numbers when I need something like: 320x50 instead I'm getting 0, as I'm not sure how to exactly extract something like this. If it was consistent I could easily do LEFT or RIGHT formula's to grab it but as you can see the data varies.
The result that I'm looking for is something along the lines of:
A | B
Example_Number_320x50_fifty_five | 320x50
Example_Number_One_300x250_hundred | 300x200
Example_Number_two_fifty_728x49 | 728x49
Any help would be much appreciated! If any further clarification is needed please let me know and I'll try to explain as best as I can!
-Maykid
I would probably use a Regular Expressions UDF to accomplish this.
First, open up the VBE by pressing Alt + F11.
Right-Click on VBAProject > Insert > Module
Then you can paste the following code in your module:
Option Explicit
Public Function getPixelDim(RawTextValue As String) As String
With CreateObject("VBScript.RegExp")
.Pattern = "\d+x\d+"
If .Test(RawTextValue) Then
getPixelDim = .Execute(RawTextValue)(0)
End If
End With
End Function
Back to your worksheet, you would use the following formula:
=getPixelDim(A1)
Looking at the pattern \d+x\d+, an escaped d (\d) refers to any digit, a + means one or more of \d, and the x is just a literal letter x. This is the pattern you want to capture as your function's return value.
Gosh, K Davis was just so fast! Here's an alternate method with similar concept.
Create a module and create a user defined function like so.
Public Function GetPixels(mycell As Range) As String
Dim Splitter As Variant
Dim ReturnValue As String
Splitter = Split(mycell.Text, "_")
For i = 0 To UBound(Splitter)
If IsNumeric(Mid(Splitter(i), 1, 1)) Then
ReturnValue = Splitter(i)
Exit For
End If
Next
GetPixels = ReturnValue
End Function
In your excel sheet, type in B1 the formula =GetPixels(A1) and you will get 320x50.
How do you create a user defined function?
Developer tab
Use this URL to add Developer tab if you don't have it: https://www.addintools.com/documents/excel/how-to-add-developer-tab.html
Click on the highlighted areas to get to Visual Basic for Applications (VBA) window.
Create module
Click Insert > Module and then type in the code.
Use the user defined function
Note how the user defined function is called.
This is a weird kind of double quotes that I'm having to deal with from a text file:
Here's the text the way my clipboard manages it:
II=" alt="“”" />][N
The point is: I am trying to use StrReplace() to detect that string and replace it, but it doesn't find the content that my clipboard gets by copy & paste.
This doesn't find anything to replace by foo:
fixedContent := StrReplace(myContent, "II="" alt=""“”"" />][N", "foo")
It seems that “” is not the same as .
Maybe I have to use a special character?
The characters “” the same as , it's just different fonts.
myContent = <IT="" alt="“”" />][Nebula]
find = IT="" alt="“”" />][N
replaceWith = foo
fixedContent := StrReplace(myContent, find, replaceWith)
msgbox % fixedContent
Try this
fixedContent:=StrReplace(myContent, "“”", "foo")
How to type WORD vv anywhere, and get the browser to open a link containing WORD in it? I know the script must have
Run, browserpath www.example.com/x/y/z/WORD.html
but I don't know what to do next.
I would use something like this:
:*:vv::
InputBox, UserInput, WORD, Enter a WORD, , 200, 120
if not ErrorLevel
{
; remove first and last white spaces
UserInput := trim(UserInput)
; replace all middle white spaces with +
UserInput := StrReplace(UserInput, A_Space , "+", UserInput)
Run, "browserpath" "www.example.com/x/y/z/%UserInput%.html"
}
return
Examples:
; google with the default browser
Run, https://www.google.com/search?hl=en&q=%UserInput%
; google images with IE
Run, iexplore.exe "https://images.google.com/images?hl=en&##"
; google autohotkey with another browser
Run, "browserpath" "https://www.google.com/search?sitesearch=ahkscript.org&q=%UserInput%"
; autohotkey.com
https://www.autohotkey.com/search/search.php?query_string=%UserInput%
; autohotkey manual
https://www.google.com/search?sitesearch=ahkscript.org&q=%UserInput%
; wikipedia
https://en.wikipedia.org/wiki/Special:Search?search=%UserInput%&go=Go
In an autohotkey script I was trying to assign a text string to a variable. Can anyone spot why this doesn't work, it looks just like some provided examples? I don't need the variable anymore, but now I'm just curious what I did wrong...
myvar := % "foo" ; creates global variable myvar, but has no contents
I know you could just say myvar = foo
but leaving quotes off a fixed text string just makes me cringe. I even had it working but didnt' save my file before making 'a few harmless cosmetic edits.' I click on the "H" task
icon near the clock, use menu File / show variables to verify the empty contents...
Okay, so we assign a value to a variable:
eval_this:= "harry"
If you do it this way, you just read the contents of the variable:
msgbox %eval_this% ;=harry
Of course, here, the text is not evaluated - "eval_this" is just text to ahk:
msgbox eval_this ;= eval_this
This method is called a "Forced Expression" - which is what you are looking to do. It tries to read the text string as if it were code. It isn't reading the contents of any variable, it is looking at the text and forcing it to become a variable (it's sort of the same thing, but not really)
msgbox % eval_this ;= harry
This also gets us harry, and you can see how we are reading the variable:
test := eval_this
msgbox %test% ;=harry
Same thing, different approach (forcing the text to become a variable):
test = % eval_this
msgbox %test% ;=harry
Consider this, where we force both text strings into their actual values
eval_this := "harry"
this_too := " and bob"
test = % eval_this this_too
msgbox %test% ;= harry and bob
Okay, now that you've got all that, here is a practical application. We will force the value of the text string to be a variable. Since we've actually defined what "alert" is, then the gosub will call that definition. Pop this into a script and run it:
eval_this := "alert"
gosub % eval_this
exit ;we are finished with the demo, so end here
alert:
msgbox harry
return
I am using ruby on rails but that does not matter much for this question. Let's say that i have a statement like this
error = 'this is an error message'
I have noticed that I end up doing this a lot
error = 'this is an error message'
puts "error = #{error.inspect}"
I am sure a macro can be written which would take the work on the left hand side of left most = and then create another line along with template shown above.
I am using mvim on mac. Any pointer in terms of where I should start to look for developing what I want.
Try snipmate:
http://www.vim.org/scripts/script.php?script_id=2540
I recorded a simple macro that does your sample. To record a macro type q followed by what register you want the macro to be put in (convention calls for qq). To play the macro type # then the macro register. You can view this at :help recording
To write the macro, use the following commands (and here is how is should look in the register)
^yEoputs "error = #{^Op.inspect}"^[
^ moves to the first non whitespace character of the line
yE yanks to the end of the space separated word.
o Puts you in insert mode on the next line
puts "error = #{ is the text that you type out
^O is ctrl+O (capital letter o) - this allows the next, and only the next command to be run in command mode, which is...
p Puts the yanked word, after this command is run you're still in insert mode
.inspect}" is the text that you type and finally...
^[ is Esc
I would go for:
nnoremap µ :s/^\s*\(\k\+\)\s*=.*/&\rputs "\1 = #{\1.inspect}"/<cr>
:s presents the advantage of doing the job plus matching the assigned variable if any. Doing the same thing with classical commands like yw, p, etc would be more cumbersome.
If the template become more complex, we can rely on template-file expanders as long as they easily permit to call viml function like matchstr(). Of course, in that case I would use mu-template with the following template-file:
VimL:" $Id: {rtp}/template/ruby/inspect.template
VimL: let s:value_start = '¡'
VimL: let s:value_end = '¡'
VimL: let s:reindent = 1
VimL: let s:marker_open = '<+'
VimL: let s:marker_close = '+>'
VimL: let s:varname = matchstr(getline(line('.')-1), '^\s*\zs\k\+\ze\s*=')
VimL: if empty(s:varname) |throw "the previous line don't assign any variable" |endif
puts "¡s:varname¡ = #{¡s:varname¡.inspect}"<++>
VimL:"vim: encoding=utf-8
If you're doing these on the fly, a snipmate snippet could look like this:
${1:error} = '${2:error message here}'
puts "error = #{$1.inspect}"
If, on the other hand you're just wanting to output pre-existing variables for debugging purposes. Nick-Canzoneri's macro may be more useful.