Advertisement
biud436

Message Handler - RGSS3 Scripts

Mar 2nd, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.23 KB | None | 0 0
  1. # Author : 러닝은빛(biud436)
  2. # Date : 2015.05.10
  3. # Update : 2015.06.12
  4. module Message
  5.   # 데이터 가져오기
  6.   system = load_data("Data/System.rvdata2")
  7.   Game_Title = system.game_title.to_s.clone
  8.   system = nil
  9.  
  10.   # 게임 핸들 획득(ANSI)
  11.   FindWindowA  = Win32API.new('User32','FindWindowA','pp','l')
  12.  
  13.   # 메시지 함수
  14.   GetMessage = Win32API.new('user32','GetMessage','plll','s')
  15.   PeekMessage = Win32API.new('user32','PeekMessage','pllll','s')
  16.   TranslateMessage = Win32API.new('user32','TranslateMessage','p','s')
  17.   PM_REMOVE = 1
  18.   PM_NOREMOVE = 0
  19.  
  20.   # 메시지 목록
  21.   WM_KEYDOWN = 0x0100 #256
  22.   WM_KEYUP = 0x0101 #257
  23.   WM_CHAR = 0x0102 #258
  24.   WM_MOUSEMOVE = 0x0200 # 512
  25.   WM_LBUTTONDOWN = 0x0201 # 513
  26.  
  27.   # C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\WinUser.h
  28.  
  29.   # 메시지 구조체
  30.   MESSAGE = 1
  31.   WPARAM = 2
  32.   LPARAM = 3
  33.  
  34.   extend self
  35.  
  36.   # 윈도우 핸들
  37.   def handle_a
  38.     return FindWindowA.call("RGSS Player",Game_Title)
  39.   end
  40.  
  41.   # 메시지 함수
  42.   def result
  43.     msg = [0,0,0,0,0].pack('lllll') + [0,0].pack('ll')
  44.     GetMessage.call(msg,handle_a,0,0)
  45.     TranslateMessage.call(msg)
  46.     return msg
  47.   end
  48.  
  49.   # 메시지 큐
  50.   def msg_q
  51.     return Message.result.unpack('llllll')
  52.   end
  53.  
  54.   # 상위 16비트 추출
  55.   def hiword(x)
  56.     x >> 16
  57.   end
  58.  
  59.   # 하위 16비트 추출
  60.   def loword(x)
  61.     x & 0xffff
  62.   end
  63.  
  64.   # 메시지 처리
  65.   def call_message
  66.     case msg_q[MESSAGE]
  67.     when WM_KEYDOWN
  68.       return p "키를 눌렀습니다 : #{msg_q[WPARAM]}"
  69.     when WM_KEYUP
  70.       return p "키를 뗐습니다"
  71.     when WM_MOUSEMOVE
  72.       return p "마우스를 움직이고 있습니다"
  73.     when WM_LBUTTONDOWN
  74.       return p "왼쪽 마우스 버튼을 눌렀습니다"
  75.     end
  76.   end
  77.  
  78.   # 메시지 루프(프레임워크와 연결)
  79.   def update
  80.     return Message.call_message
  81.   end
  82. end
  83.  
  84. class Scene_Base
  85.   #--------------------------------------------------------------------------
  86.   # * Update Frame (Basic)
  87.   #--------------------------------------------------------------------------
  88.   def update_basic
  89.     Graphics.update
  90.     Input.update
  91.     update_all_windows
  92.     Message.update
  93.   end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement