Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from eudtrg import *
- class KeyState:
- _base_address = 0x596A18
- def __init__(self, *keys):
- '''
- usage:
- 1) You can use one-length-alphabet to use
- ex) ks = KeyState( 'I', 'J', 'K', 'L' )
- 2) You can also use by virtual key code
- VK Key Codes : http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
- ex) ks = KeyState( 'A', 0x1B, 0x15 ) # 0x1B : VK_ESCAPE. 0x15 : VK_HANGUEL
- ex) ks = KeyState( '1', '2' ) # 1 key, 2 key. This is different with KeyState(1, 2),
- Note that VK code for 1 is 0x31
- '''
- keys = list(keys)
- # convert to VK-Codes
- for i, key in enumerate(keys):
- if isinstance(key, str):
- key = key.upper() # transform to uppercase
- assert len(key) == 1 and ord('0') <= ord(key) <= ord('Z'), "에러: 키는 한글자 알파벳&숫자 스트링, 혹은 1부터 255까지의 수여야 합니다. '%s' 해석 불가." % key
- keys[i] = ord(key)
- self.dictionary = dict()
- # check for existence from 1 ( VK_LBUTTON ) to 0xFE ( VK_OEM_CLEAR )
- for i in range(0, 0x100):
- if i in keys:
- self.dictionary[i] = {"curr":EUDCreateVariables(1), "prev":EUDLightVariable()}
- def newlyKeyDown(self, key):
- if isinstance(key, str):
- key = ord(key.upper()) # transform to uppercase
- assert key in self.dictionary, "에러: 해당 키 '%s' 는 초기화 시점 포함되지 않았습니다." % key
- return [ self.dictionary[key]["prev"].Exactly(0), self.dictionary[key]["curr"].Exactly(1) ]
- def newlyKeyUp(self, key):
- if isinstance(key, str):
- key = ord(key.upper()) # transform to uppercase
- assert key in self.dictionary, "에러: 해당 키 '%s' 는 초기화 시점 포함되지 않았습니다." % key
- return [ self.dictionary[key]["prev"].Exactly(1), self.dictionary[key]["curr"].Exactly(0) ]
- def currentlyKeyDown(self, key):
- if isinstance(key, str):
- key = ord(key.upper()) # transform to uppercase
- assert key in self.dictionary, "에러: 해당 키 '%s' 는 초기화 시점 포함되지 않았습니다." % key
- return self.dictionary[key]["curr"].Exactly(1)
- def currentlyKeyUp(self, key):
- if isinstance(key, str):
- key = ord(key.upper()) # transform to uppercase
- assert key in self.dictionary, "에러: 해당 키 '%s' 는 초기화 시점 포함되지 않았습니다." % key
- return self.dictionary[key]["curr"].Exactly(0)
- def update(self):
- '''
- update previous values. I recommend to put this at the end of your trigger cycle
- '''
- # update previous values
- for key in self.dictionary:
- Trigger(
- conditions = self.dictionary[key]["curr"].AtLeast(1),
- actions = self.dictionary[key]["prev"].SetNumber(1)
- )
- Trigger(
- conditions = self.dictionary[key]["curr"].Exactly(0),
- actions = self.dictionary[key]["prev"].SetNumber(0)
- )
- # update current values
- for p in range(0, 0x100 // 4):
- broken = None
- for i in range(4):
- if 4*p+i in self.dictionary:
- if broken == None:
- broken = f_dwbreak(f_dwread_epd(EPD(self._base_address) + p))
- self.dictionary[4*p+i]["curr"] << broken[2+i]
- LoadMap('load.scx')
- abcd_keymachine = KeyState('a', 'b', 'c', 'd')
- start = NextTrigger()
- if EUDWhile(Always()):
- abcd_keymachine.update()
- # Turbo trigger
- DoActions(SetDeaths(203151, SetTo, 0, 0))
- # to display text for P1
- f_setcurpl(P1)
- if EUDIf( abcd_keymachine.newlyKeyDown('a') ):
- DoActions([DisplayText("방금 막 a키를 누르셨네요")])
- EUDEndIf()
- if EUDIf( abcd_keymachine.newlyKeyUp('b') ):
- DoActions([DisplayText("방금 막 b키를 떼셨네요")])
- EUDEndIf()
- if EUDIf( abcd_keymachine.currentlyKeyDown('c') ):
- DoActions([DisplayText("지금 c키 누르고 계셔요")])
- EUDEndIf()
- if EUDIf( abcd_keymachine.currentlyKeyUp('d') ):
- DoActions([DisplayText("지금 d키 안누르고 계셔요")])
- EUDEndIf()
- EUDDoEvents()
- EUDEndWhile()
- SaveMap('result.scx', start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement