Community
SCI Programming => SCI Syntax Help => Topic started by: totenmaske on July 19, 2012, 07:56:25 AM
-
I've been trying to add a new loop cycle for the diagonal movements. I was using a bit of code that Doan put up when he was getting help with his running issue.
(if (== (send pEvent:type) evKEYBOARD)
(switch(send pEvent:message)
(case KEY_END
Print("END")
(send gEgo:setDirection(DOWNLEFT)setLoop(5))
)
(case KEY_HOME
Print("HOME")
(send gEgo:setDirection(UPLEFT)setLoop(7))
)
(case KEY_PAGEDOWN
Print("PAGE DOWN")
(send gEgo:setDirection(DOWNRIGHT)setLoop(4))
)
(case KEY_PAGEUP
Print("PAGE UP")
(send gEgo:setDirection(UPRIGHT)setLoop(6))
)
)
) For some reason i can't even get the Print message to appear, let alone the movement when i press the keys; Home, end, pageup or pagedown.
I changed the key required to start the even to Z and X to see if i put the code in the wrong spot, but when i have those keys it works just fine. Is there a hidden code somewhere for these movements? I found this little bit of code in the Control.sc under the DSelector class. it is the only other place i can find something involving these 4 keys.
(switch( (send pEvent:type) )
(case evKEYBOARD
(send pEvent:claimed(TRUE))
(switch( (send pEvent:message) )
(case KEY_HOME
(self:retreat(50))
)
(case KEY_END
(self:advance(50))
)
(case KEY_PAGEUP
(self:advance(- y 1))
)
(case KEY_PAGEDOWN
(self:retreat(- y 1))
)
(case KEY_DOWN
(self:advance(1))
)
(case KEY_UP
(self:retreat(1))
)
(default
(send pEvent:claimed(FALSE))
)
)
)
*EDIT*
I just tried to see, if for some reason the buttons had the wrong values associated with them. I couldn't even get the values of these keys unless i was holding down Ctrl at the same time though.
-
Totenmaske, I have an answer for this. As you pointed out, it's because the raw keyboard input does not correspond to the values specified in keys.sh. Before performing your event checking, make this kernel call:
MapKeyToDir(pEvent)
Then your code should work properly.
This will translate the raw keyboard input into the key constants specified in keys.sh (KEY_UP, KEY_DOWN, etc). I'm guessing that this call exists so that the same key codes work regardless of which OS the SCI VM is running on. So the implementation of the VM on different OS's perform a different key translation in the MapKeyToDir call, but the SCI code never needs to change.
-
I am not really trying to use this for movement, but I am also struggling to get key presses handled. I want to use the arrow keys for a bit of arcade action, but like Totenmaske, I am not getting the responses that I am expecting. With the super:handleEvent line removed, I can get it to respond with both up and right using the keypad (but I think it is from the 8 and the 6 being pressed not from the arrows when numlock is off)... however the arrow keys, which are the ones that will probably be used by most people for this part are not returning true.
Some help on getting this bit figured out would be great
(method (handleEvent pEvent)
// (super:handleEvent(pEvent)) // works when removed
(if (== evKEYBOARD (send pEvent:type))
MapKeyToDir(pEvent)
(switch (send pEvent:message)
(case KEY_UP Print("up"))
(case KEY_8 Print("up"))
(case $4D00 Print("right"))
(case $36 Print("right"))
)
)
)
-
I could probably explain it if the reverse were true of it working with the cursor keys, but not the pad. There is something broken in the official DOSBox 0.74 that it usually does not recognize pad key presses unless you repeatedly tap the Num lock. This has been fixed in SVN. Just to be sure, try an SVN build.
-
Well I managed to get all the responses that I was looking for. Apparently the arrow keys somehow or other are mapped to joystick events. Once I added in an additional check for those too, all of my issues seemed to clear right up. This is the code I ended up using.
(method (handleEvent pEvent)
(super:handleEvent(pEvent))
(if (== evKEYBOARD (send pEvent:type))
(switch (send pEvent:message)
(case KEY_UP Print("up"))
(case KEY_8 Print("up"))
(case KEY_RIGHT Print("right"))
(case KEY_6 Print("right"))
(case KEY_DOWN Print("down"))
(case KEY_2 Print("down"))
(case KEY_LEFT Print("left"))
(case KEY_4 Print("left"))
)// ends switch
)// ends keyboard
(if (== evJOYSTICK (send pEvent:type))
(switch (send pEvent:message)
(case UP Print("up"))
(case RIGHT Print("right"))
(case DOWN Print("down"))
(case LEFT Print("left"))
)// ends switch
)// ends joystick
)// ends method
Hopefully checking for key direction and the key number will eliminate any user confusion with num lock being on or off in the keyboard section. And like I said the arrow keys seem to correspond to joystick events so that section covers those. This bit of info will come in handy for the Punch Out script when I make it back to working on Fabulous Las Vegas. But for my current project, I am back to keeping it moving forward.