ahwa Posted February 5, 2017 Share Posted February 5, 2017 (edited) import Keysimport Avatar ModEnable = True def New_PlayerAvatar(current, isDown, key, mods): global ModEnable if ModEnable and key == Keys.KEY_NUMPAD0 and isDown: ModEnable = False message = '<font color="#FF0000">' + 'ModStop' + '</font>' MessengerEntry.g_instance.gui.addClientMessage(message) if not ModEnableand and key == Keys.KEY_NUMPAD0 and isDown: ModEnable= True message = '<font color="#7BFF00">' + 'ModStart' + '</font>' MessengerEntry.g_instance.gui.addClientMessage(message) return Old_PlayerAvatar(current, isDown, key, mods) Old_PlayerAvatar = Avatar.PlayerAvatar.handleKey Avatar.PlayerAvatar.handleKey = New_PlayerAvatar Не работает Методы Ошибки? Edited February 5, 2017 by ahwa @ Quote Link to comment Short link Share on other sites More sharing options...
Armagomen_UA Posted February 6, 2017 Share Posted February 6, 2017 (edited) import Keys from gui import InputHandler from gui.shared import events, g_eventBus from gui.app_loader.settings import APP_NAME_SPACE class HotKey(object): def __init__(self): g_eventBus.addListener(events.AppLifeCycleEvent.INITIALIZING, self.battleLoading) g_eventBus.addListener(events.AppLifeCycleEvent.DESTROYED, self.destroyBattle) self.hot_key = getattr(Keys, "KEY_NUMPAD0", None) self.enable = False def battleLoading(self, event): if event.ns == APP_NAME_SPACE.SF_BATTLE: InputHandler.g_instance.onKeyDown += self.key_event InputHandler.g_instance.onKeyUp += self.key_event def destroyBattle(self, event): if event.ns == APP_NAME_SPACE.SF_BATTLE: InputHandler.g_instance.onKeyDown -= self.key_event InputHandler.g_instance.onKeyUp -= self.key_event def key_event(self, event): if self.hot_key is not None: # key down event if event.key == self.hot_key and event.isKeyDown(): self.enable = True if not self.enabe else False message = '<font color="#FF0000">ModStop</font>' if not self.enable else '<font color="#7BFF00">ModStart</font>' # message = '<font color="%s">%s</font>' % (("#FF0000", "ModStop") if not self.enable else ("#7BFF00", "ModStart")) MessengerEntry.g_instance.gui.addClientMessage(message) # import the MessengerEntry print 'key is Down' # key up event # if event.key == self.hot_key and not event.isKeyDown(): # print 'key is UP' HotKey() Edited February 6, 2017 by Armagomen_dev @ Quote Link to comment Short link Share on other sites More sharing options...
ahwa Posted February 6, 2017 Author Share Posted February 6, 2017 if event.key == self.logs_altmode_key and event.isKeyDown(): is my key?? self.logs_altmode change event.key == KEY_NUMPAD0 Or no effect @ Quote Link to comment Short link Share on other sites More sharing options...
Armagomen_UA Posted February 6, 2017 Share Posted February 6, 2017 if event.key == Keys.KEY_NUMPAD0 and event.isKeyDown(): @ Quote Link to comment Short link Share on other sites More sharing options...
ahwa Posted February 7, 2017 Author Share Posted February 7, 2017 thank you @ Quote Link to comment Short link Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.