Jump to content

do Send with special char stored in variable

Recommended Posts

short story:

; line 2 in $file reads "F5", no quotes
$var = FileReadLine($file,2)

does not work. Now i know since it's a function key (F1-F10) i could check it with a series of if-else's (if i dont stumble across a switch statement - that accepts strings, or i change var to int without the F), but i'd rather do this proper (and keep the code vaguely readable). Anyway, i was just wondering if this was possible.

Also, i can hear windows' "what-the-hell-am-i-supposed-to-do-with-that-keypress" error sound, so it's pressing _some_ key...


Long story:

settings.ini (i added line numbers here they're not in file):

line1: // comment explaining

line2: F5

line3: // another comment explaining

line4: F9

line5: //EOF just in case



; ... bit of code focusing on right window, settings mouse/pixel to local window etc...
$file = FileOpen("settings.ini", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open settings.ini")

$KeyOne = FileReadLine($file,2)
$KeyTwo = FileReadLine($file,4)


; bit of code

HotKeySet("{F11}", "PauseMacro")  ; just including
HotKeySet("{PAUSE}", "Terminate") ; cause this works

; more code including main loop


; end mainloop

Func CheckIt()
    $PixelX = 36
    $PixelY = $WinH - 36; $WinH = window height
    $color = PixelGetColor($PixelX,$PixelY)
    $blue = mod($color, 256)
    IF $blue > 80 then
        Send("{$KeyOne}"); as said above, Send("{F5}") works fine


Edited by SirBob
Link to comment
Share on other sites


; line 2 in $file reads "F5", no quotes
$var = FileReadLine($file,2)
Send("{" & $var & "}")

Edit: or you could use this function and do this.

; line 2 in $file reads "F5", no quotes
$var = FileReadLine($file,2)

Func _ExpandVarStrings($sInput)
    Dim $aPart = StringSplit($sInput,'$')
    If @error Then
        Return $sInput
    Dim $sOut = $aPart[1], $i = 2, $Var = ''
;loop through the parts
    While $i <= $aPart[0]
        $Var = Eval ($aPart[$i])
        If $Var <> '' Then;this part is an expandable Variable
            $sOut = $sOut & $Var
            $i = $i + 1
            If $i <= $aPart[0] Then $sOut = $sOut & $aPart[$i]
        ElseIf $aPart[$i] = '' Then;a double-$ is used to force a single $
            $sOut = $sOut & '$'
            $i = $i + 1
            If $i <= $aPart[0] Then $sOut = $sOut & $aPart[$i]
        Else;this part is to be returned literally
            $sOut = $sOut & '$' & $aPart[$i]
        $i = $i + 1
    Return $sOut

Edited by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

hmm that second one sure looks impressive. but since i'm the only one seeing code, the first one's much clearer and suits my needs perfectly, i'll go with that.

i'm such an idiot, never even occurred to me that it was actually sending along a string to a "Send" function to be parsed (... i dunno i guess i thought it was magic or something). So string concatenating is just what i need,


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...