Recent Posts
Recent Comments
04-18 12:46
관리 메뉴

동글동글 라이프

Win32::GuiTest - Perl GUI Test Utilities. 본문

개발자 이야기/Perl

Win32::GuiTest - Perl GUI Test Utilities.

동글동글라이프 2008. 11. 17. 20:04

최근 Gtk를 사용하여 이것저것 실습을 하던 중

perl로 Windows api를 다루는 모듈은 없을까 cpan에서 

Search를 해보던중 흥미로운 모듈을 발견했다.


Win32::GuiTest

Perl GUI Test Utilities. 
Win32-GuiTest-1.56****  (2 Reviews) - 02 Oct 2008 - Dmitry Karasik


Perl GUI Test Utilities...

갱신된지 얼마 되지 않은 이 모듈은 뭘까?

  use Win32::GuiTest qw(FindWindowLike GetWindowText 
    SetForegroundWindow SendKeys);

  $Win32::GuiTest::debug = 0; # Set to "1" to enable verbose mode

  my @windows = FindWindowLike(0, "^Microsoft Excel", "^XLMAIN\$");
  for (@windows) {
      print "$_>\t'", GetWindowText($_), "'\n";
      SetForegroundWindow($_);
      SendKeys("%fn~a{TAB}b{TAB}{BS}{DOWN}");
  }

코드를 대략 살펴보니 보니  FindWindowLike 함수를 사용하여 윈도우 창을 찾고

그 창에 여러 키를 입력하는 코드였다.

일단 설치를 하고 SYSNOPSIS의 기본 코드를 실행을 시켜보니...

(나의 스타일이 결과부터 보자식이라;;)


실행과 동시에 종료되어 버렸다...

아.. 그렇다;; Excel창이 없으니 자동 종료가 되어버렸....


Excel을 실행 시킨후 다시 perl 프로그램을 실행시키니



헉... 엑셀 시트에 n과 a, b 문자를 출력하고 있다.

왠지 흥미롭지 않는가? +_+



전체적으로 key 뿐만아니라 Mouse 까지 다루고 있으며

SendKeys함수의 세부적인 Action 까지 상세하게 다루고 있다.

이것 하나만 있으면 엑셀을 사용하는 사람은... 

조금 더 편하게 문서를 정리 할 수 있지 않을까?




사용법을 완벽하게 익히기에 예제가 조금 부족한 느낌이 들었는데


Win32::GuiTest::Examples

collection of the scripts from eg 
Win32-GuiTest-1.56****  (2 Reviews) - 02 Oct 2008 - Dmitry Karasik


예제까지 확실하게 Cpan에 올려놓으셨다..




Examples에는 총 26개의 예제가 있으며 재밌는 코드를 소개하자면!!


   #!perl -w
    #
    # Draw an X and a box around it
    #
    use strict;
    use Win32::GuiTest qw(FindWindowLike SetForegroundWindow 
        SendMouse MouseMoveAbsPix SendLButtonDown SendLButtonUp);
    
    system("start /max mspaint");
    sleep 2;
    my @windows = FindWindowLike(0, "Paint", "");
    die "Could not find Paint\n" if not @windows;
    
    SetForegroundWindow($windows[0]);
    sleep 1;
    
    #Using low level functions
    MouseMoveAbsPix(100,100);
    SendLButtonDown();
    MouseMoveAbsPix(300,300);
    SendLButtonUp();
    
    
    sleep 1;
    
    MouseMoveAbsPix(100,300);
    SendLButtonDown();
    MouseMoveAbsPix(300,100);
    SendLButtonUp();
    
    sleep 1;
        
    MouseMoveAbsPix(100,100);
    SendLButtonDown();
    MouseMoveAbsPix(300,100);
    MouseMoveAbsPix(300,300);
    MouseMoveAbsPix(100,300);
    MouseMoveAbsPix(100,100);
    SendLButtonUp();


윈도우 창을 찾을 때 한글을 고려하자면...

my @windows = FindWindowLike(0, "Paint", "");

이런식으로 고쳐주셔야...

my @windows = FindWindowLike(0, "제목 없음 - 그림판", "");



시스템 함수를 사용하여 mspaint 를 실행시킨후

마우스를 이동시키며 정사각형안에 X가 들어있는 그림을 그리는 코드이다.

실용성은 없어보이지만 볼거리가 있는 코드라 넣어놓는다






그 이외에...

계산기를 실행하여 자동으로 숫자와 연산자를 입력하여 결과값을 구해주는 코드

노트패드에 글을 쓴 뒤 자동으로 종료해주는 코드, 

//이건 재미있어서 실행파일로 만들어 보았다.




카드놀이를 실행한뒤 이것저것 만져주는 코드,

컴퓨터의 제어판의 여러 목록들을 실행하고 종료하는 코드,

윈도우의 모든 창을 찾아주는 코드,

해당 창을 찾아 캡쳐를 한 뒤 자동으로 저장해주는 코드  등 // 위험한 느낌이 들었던..;

유용한 코드들이 많이 보였다.



보안적인 면에서는 백그라운드로 실행되는 것이 아니기 때문에

해킹툴보다는 조크바이러스 정도로 밖에 안될듯...


나 너 해킹했어요~ 이렇게 알려주는 것이라...

비주얼 적인 면에서는 효과가 뛰어날 것이라 본다.




오토마우스 오토키보드 같은 프로그램이 있긴 하지만...

perl을 사용하여 직접 프로그램을 만들어 보는것도

흥미로운 작업이 아닐까 생각된다^^


'개발자 이야기 > Perl' 카테고리의 다른 글

perl을 사용한 HTML Parser  (1) 2008.11.23
웹용 코드 테스터  (4) 2008.11.21
음악을 들어보자 #5  (5) 2008.11.13
CPAN Author 등록하기  (0) 2008.11.13
perl Array & C language Array  (4) 2008.11.03
Comments