본문 바로가기
programming language/Autohotkey

Autohotkey ScriptControl 을 이용하여 VBScript, JScript실행하기

by __observer__ 2014. 3. 23.
반응형

아래 포스팅에서 밝힌 바와 같이 Autohotkey에서는 ComObjCreate() 함수를 사용하여 COM object 를 사용 할 수 있습니다.

  

2012/08/16 - [programming language/Autohotkey] - Autohotkey_L을 이용한 MS Word 자동화


2012/06/24 - [programming language/Autohotkey] - Autohotkey_L 로 구글 검색하기


2012/05/21 - [programming language/Autohotkey] - Autohotkey_L Text to Speech


오늘은 ComObjCreate()를 사용하여 Autohotkey에서 VBScript 과 JScript 언어를 실행하는 방법에 대해 알아보려 합니다.

 

저는 현재 윈도우 7 64 비트 환경에 Autohotkey UNICODE 64 비트를 설치했었는데~ 64 비트에서는 ComObjCreate("ScriptControl") 가 정상적으로 실행되지 않더군요.

 

그래서 UNICODE 32 비트를 설치했습니다.

 

샘플로 실행해본 코드는 인터넷에서 찾아본 코드들로 다음과 같습니다.

 

첫 번재로 VBScript 입니다.

 

sc := ComObjCreate("ScriptControl")

 

;// define the Language

sc.Language := "VBScript"

 

;// define the VBScript

script =

(

Dim string

Arr = Array("Auto", "Hot", "key!")

For Each i In Arr

string = string & i

Next

MsgBox "Joined Array Elements:" & vbCR & string, 64, "VBScript MsgBox"

)

 

;// execute the VBScript

sc.ExecuteStatement(script)

 

;// extract values from the VBScript

MsgBox, 64, AutoHotkey MsgBox, % "Joined Array Elements:`n" sc.Eval("Arr(0) & Arr(1) & Arr(2)")

 

다음과 같은 실행 결과가 나오더군요.

 

두 번째로 JScript예제 입니다. 아래 예제는 Autohotkey 에서 JScript를 사용하여 URI Encoding 하는 예제 인데~

 

 

UriEncode(Uri)

{

oSC := ComObjCreate("ScriptControl")

oSC.Language := "JScript"

Script := "var Encoded = encodeURIComponent(""" . Uri . """)"

oSC.ExecuteStatement(Script)

Return, oSC.Eval("Encoded")

}

 

UriDecode(Uri)

{

oSC := ComObjCreate("ScriptControl")

oSC.Language := "JScript"

Script := "var Decoded = decodeURIComponent(""" . Uri . """)"

oSC.ExecuteStatement(Script)

Return, oSC.Eval("Decoded")

}

 

keyword := UriEncode("한글")

 

MsgBox % keyword

   

한글이라는 글자가 다음과 같이 encoding 돼서 나오더군요.


반응형

댓글