Construct Keyboard in python

This forum is currently in read-only mode.
From the Asset Store
Casino? money? who knows? but the target is the same!
  • hey im new to construct but have done c++ for years now. I love construct but im having a few problems using keyboard input in python within the scrip editor. When i say something like

    if MouseKeyboard.KeyDown(ineedkeydetails)

    StartGameButton.X = 40

    I cant find a way to find the ID of the keyboard controls such as Left arrow. I have read the tutorials and i can use pygame for keyboard input however i was just wondering if someone could tell me how to locate the ID's of the keys. Inside the layout properties it lists controls such as Move up as Up arrow but when used as an ID i get the same error and the script editor doesent auto complete the parameters just wondering if anyone can help me out if not no worries thanks all.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Another Python user!

    You may have discovered a bug in the Python support for this feature:

    I've been looking at this for the past 30 mins and haven't quite figured out what is wrong but have some ideas:

    The implementation of the MouseKeyBoard plugin is here: ... d/Main.cpp

    If you look at the actual functions when you normally add an event:

    ADDPARAMCOMBO("Key", "Key to check if down.", keysCombo);
    	ADDCND("Key is down?", "Keyboard", "%o Key %0 is down", &ExtObject::cKeyDown, "KeyDown", 0);
    That registers this callback function:
    [code:10k3mnnh]long ExtObject::cKeyDown(LPVAL params)
    	return KeyIsDown(keyTable[params[0].GetInt()].vk);
    This returns the value for the virtual keys:
    So it appears that all you should have to do is feed in the key name which would be "Left arrow".  That of course, doesn't work and feeding in key codes doesn't make sense since it won't be found in the lookup table.
    So I guess we need to find the Python implementation code and see what is going wrong.  I don't know where it is so maybe Ashley or ROjohound may have some ideas.
  • ok thanks for the infromation im new to constructor and i am enjoying it and this seems to be the only problem i have really had and it cn be solved by using the event editor anyway but i really wanted to implement the controls in python for a college project that requires classes to be used. Anyway thanks for the reply and the information i guess ill just use pygame until something else is resolved .

  • Ok, I figured it out.

    The keycode is the index into the keyTable[] array on the following page: ... d/Main.cpp


    ControlTableEntry keyTable[] = {

    {VK_LBUTTON, "Left mouse button"},

    {VK_MBUTTON, "Middle mouse button"},

    {VK_RBUTTON, "Right mouse button"},

    {VK_TAB, "Tab"},

    {VK_RETURN, "Enter"},

    {VK_SHIFT, "Shift"},

    {VK_LSHIFT, "Shift (left)"},

    {VK_RSHIFT, "Shift (right)"},

    {VK_CONTROL, "Control"},

    {VK_LCONTROL, "Control (left)"},

    {VK_RCONTROL, "Control (right)"},

    {VK_MENU, "Alt"},

    {VK_LMENU, "Alt (left)"},

    {VK_RMENU, "Alt (right)"},

    {VK_PAUSE, "Pause"},

    {VK_ESCAPE, "Escape"},

    {VK_SPACE, "Space"},

    {VK_HOME, "Home"},

    {VK_END, "End"},

    {VK_UP, "Up arrow"},

    {VK_DOWN, "Down arrow"},

    {VK_LEFT, "Left arrow"},

    {VK_RIGHT, "Right arrow"},

    {VK_INSERT, "Insert"},

    {VK_DELETE, "Delete"},

    So if you wanted the space key you would do a:

    if MouseKeyboard.KeyDown(16):

    do your stuff

    For readability, you will probably want to just statically define the mapping in a start of layout event.


  • thanks a freaking truck load you saved me a lot of time plus i was getting other errors using pygame, so thanks again for helping me out

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)