Construct Keyboard in python

For questions about using Classic.

Post » Wed May 05, 2010 1:28 pm

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 :P just wondering if anyone can help me out if not no worries thanks all.
B
1
G
2
Posts: 3
Reputation: 631

Post » Wed May 05, 2010 2:50 pm

Another Python user! :wink:
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:
https://construct.svn.sourceforge.net/s ... d/Main.cpp

If you look at the actual functions when you normally add an event:
[code:10k3mnnh]ADDPARAMCOMBO("Key", "Key to check if down.", keysCombo);
ADDCND("Key is down?", "Keyboard", "%o Key %0 is down", &ExtObject::cKeyDown, "KeyDown", 0);
[/code:10k3mnnh]

That registers this callback function:
[code:10k3mnnh]long ExtObject::cKeyDown(LPVAL params)
{
return KeyIsDown(keyTable[params[0].GetInt()].vk);
}
[/code:10k3mnnh]

This returns the value for the virtual keys:
http://www.kbdedit.com/manual/low_level_vk_list.html

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.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Wed May 05, 2010 2:56 pm

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 .
B
1
G
2
Posts: 3
Reputation: 631

Post » Wed May 05, 2010 3:26 pm

Ok, I figured it out.

The keycode is the index into the keyTable[] array on the following page:
https://construct.svn.sourceforge.net/s ... d/Main.cpp

So:
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.

Cheers!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Wed May 05, 2010 4:35 pm

thanks a freaking truck load you saved me a lot of time :P plus i was getting other errors using pygame, so thanks again for helping me out
B
1
G
2
Posts: 3
Reputation: 631


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests