Jump to content
Korean Random
Van Dark

Как сделать проверку нажатия клавиши?

Recommended Posts

Кури по сорцам как работает метод handleKeyEvent

Share this post


Link to post

Short link
Share on other sites
import BigWorld, Keys
from gui import InputHandler

def onKeyDown(event):
    if event.isKeyDown() and BigWorld.isKeyDown(Keys.KEY_TAB):
        <твой код>

InputHandler.g_instance.onKeyDown += onKeyDown

 

  • Upvote 1

Share this post


Link to post

Short link
Share on other sites

Как ещё вариант, хукая handleKeyEvent.

import game
import Keys

@override(game, "handleKeyEvent")
def handleKeyEvent(base, event):
    print event.isRepeatedEvent() # detect repeated event to prevent perfomance issues
    print event.isKeyDown()
    print event.key # code from scripts/client/Keys.py, use on key up/down event for only one key
    print event.key in (Keys.KEY_LALT, Keys.KEY_RALT)
    print BigWorld.isKeyDown(Keys.KEY_LCTRL) and BigWorld.isKeyDown(Keys.KEY_H) # check if all hotkey sequence is pressed at the moment

    return base(event)

Вообще замечаю, что вместо подписки на ивент некоторые мододелы используют хук для этого.
override функцию можно взять везде

Edited by Kurzdor

Share this post


Link to post

Short link
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...