Skip to content

unable to dereference % in Execute() method #4

@bradwbradw

Description

@bradwbradw

I'm finding that % symbols seem to always seem to get interpreted literally, instead of dereferencing a variable. Tried any variation of concatenating and using expressions with same result.

using sharpAHK;
[...]
_AHK ahk = new _AHK();
 ahk.Execute(@"
            x:=""hello""
            MsgBox ""x is "". %x% 
            ");

produces:
Capture

I found two workarounds though!

  1. If I change the dereferencing character to something else, like $, then it works as expected
#
_AHK ahk = new _AHK();
 ahk.Execute(@"
            #DerefChar $
            x:=""hello""
            MsgBox ""x is "". $x$ 
            ";

Capture2

  1. Instead of initializing using new _AHK(), use the ahkGlobal.ahkdll.ExecRaw()
ahkGlobal.ahkdll = new AutoHotkey.Interop.AutoHotkeyEngine();
ahkGlobal.ahkdll.ExecRaw(@"
            x:=""hello""
            MsgBox ""x is "". %x% 
            ");

It must be something to do with escaping chars somewhere along the line between the C# verbatim string and the string that the dll executes, but i really have no idea... hope this helps someone though.

I'm not sure which workaround is more desirable. The documentation (https://www.autohotkey.com/docs/commands/_EscapeChar.htm#Related) does warn against using #DerefChar because it "does more harm than good" and won't be supported in V2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions