Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.52 KB | None | 0 0
  1. from eudtrg import *
  2.  
  3. class KeyState:
  4.     _base_address = 0x596A18
  5.     def __init__(self, *keys):
  6.         '''
  7.        usage:
  8.            1) You can use one-length-alphabet to use
  9.                ex) ks = KeyState( 'I', 'J', 'K', 'L' )
  10.            2) You can also use by virtual key code
  11.                VK Key Codes : http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
  12.                ex) ks = KeyState( 'A', 0x1B, 0x15 )    # 0x1B : VK_ESCAPE. 0x15 : VK_HANGUEL
  13.                ex) ks = KeyState( '1', '2' )           # 1 key, 2 key. This is different with KeyState(1, 2),
  14.                                                            Note that VK code for 1 is 0x31
  15.        '''
  16.         keys = list(keys)
  17.         # convert to VK-Codes
  18.         for i, key in enumerate(keys):
  19.             if isinstance(key, str):
  20.                 key = key.upper() # transform to uppercase
  21.                 assert len(key) == 1 and ord('0') <= ord(key) <= ord('Z'), "에러: 키는 한글자 알파벳&숫자 스트링, 혹은 1부터 255까지의 수여야 합니다. '%s' 해석 불가." % key
  22.                 keys[i] = ord(key)
  23.  
  24.         self.dictionary = dict()
  25.  
  26.         # check for existence from 1 ( VK_LBUTTON ) to 0xFE ( VK_OEM_CLEAR )
  27.         for i in range(0, 0x100):
  28.             if i in keys:
  29.                 self.dictionary[i] = {"curr":EUDCreateVariables(1), "prev":EUDLightVariable()}
  30.  
  31.     def newlyKeyDown(self, key):
  32.         if isinstance(key, str):
  33.             key = ord(key.upper()) # transform to uppercase
  34.         assert key in self.dictionary, "에러: 해당 키 '%s' 는 초기화 시점 포함되지 않았습니다." % key
  35.         return [ self.dictionary[key]["prev"].Exactly(0), self.dictionary[key]["curr"].Exactly(1) ]
  36.  
  37.     def newlyKeyUp(self, key):
  38.         if isinstance(key, str):
  39.             key = ord(key.upper()) # transform to uppercase
  40.         assert key in self.dictionary, "에러: 해당 키 '%s' 는 초기화 시점 포함되지 않았습니다." % key
  41.         return [ self.dictionary[key]["prev"].Exactly(1), self.dictionary[key]["curr"].Exactly(0) ]
  42.  
  43.     def currentlyKeyDown(self, key):
  44.         if isinstance(key, str):
  45.             key = ord(key.upper()) # transform to uppercase
  46.         assert key in self.dictionary, "에러: 해당 키 '%s' 는 초기화 시점 포함되지 않았습니다." % key
  47.         return self.dictionary[key]["curr"].Exactly(1)
  48.  
  49.     def currentlyKeyUp(self, key):
  50.         if isinstance(key, str):
  51.             key = ord(key.upper()) # transform to uppercase
  52.         assert key in self.dictionary, "에러: 해당 키 '%s' 는 초기화 시점 포함되지 않았습니다." % key
  53.         return self.dictionary[key]["curr"].Exactly(0)
  54.  
  55.     def update(self):
  56.         '''
  57.        update previous values. I recommend to put this at the end of your trigger cycle
  58.        '''
  59.  
  60.         # update previous values
  61.         for key in self.dictionary:
  62.             Trigger(
  63.                 conditions = self.dictionary[key]["curr"].AtLeast(1),
  64.                 actions = self.dictionary[key]["prev"].SetNumber(1)
  65.             )
  66.             Trigger(
  67.                 conditions = self.dictionary[key]["curr"].Exactly(0),
  68.                 actions = self.dictionary[key]["prev"].SetNumber(0)
  69.             )
  70.  
  71.         # update current values
  72.         for p in range(0, 0x100 // 4):
  73.             broken = None
  74.             for i in range(4):
  75.                 if 4*p+i in self.dictionary:
  76.                     if broken == None:
  77.                         broken = f_dwbreak(f_dwread_epd(EPD(self._base_address) + p))
  78.  
  79.                     self.dictionary[4*p+i]["curr"] << broken[2+i]
  80.  
  81.  
  82. LoadMap('load.scx')
  83.  
  84. abcd_keymachine = KeyState('a', 'b', 'c', 'd')
  85.  
  86. start = NextTrigger()
  87.  
  88. if EUDWhile(Always()):
  89.     abcd_keymachine.update()
  90.  
  91.     # Turbo trigger
  92.     DoActions(SetDeaths(203151, SetTo, 0, 0))
  93.  
  94.     # to display text for P1
  95.     f_setcurpl(P1)
  96.  
  97.     if EUDIf( abcd_keymachine.newlyKeyDown('a') ):
  98.         DoActions([DisplayText("방금 막 a키를 누르셨네요")])
  99.     EUDEndIf()
  100.  
  101.     if EUDIf( abcd_keymachine.newlyKeyUp('b') ):
  102.         DoActions([DisplayText("방금 막 b키를 떼셨네요")])
  103.     EUDEndIf()
  104.  
  105.     if EUDIf( abcd_keymachine.currentlyKeyDown('c') ):
  106.         DoActions([DisplayText("지금 c키 누르고 계셔요")])
  107.     EUDEndIf()
  108.  
  109.     if EUDIf( abcd_keymachine.currentlyKeyUp('d') ):
  110.         DoActions([DisplayText("지금 d키 안누르고 계셔요")])
  111.     EUDEndIf()
  112.    
  113.     EUDDoEvents()
  114.  
  115. EUDEndWhile()
  116.  
  117. SaveMap('result.scx', start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement