Author Topic: code for movement keys  (Read 3933 times)

0 Members and 1 Guest are viewing this topic.

Offline totenmaske

code for movement keys
« 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.
Code: [Select]
       (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.
Code: [Select]
(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.

« Last Edit: July 20, 2012, 01:53:06 AM by totenmaske »



Offline gumby

Re: code for movement keys
« Reply #1 on: March 16, 2013, 10:33:46 AM »
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:

Code: [Select]
  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.
« Last Edit: March 16, 2013, 10:43:37 AM by gumby »
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: code for movement keys
« Reply #2 on: July 31, 2014, 04:44:03 PM »
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

Code: [Select]
(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"))
    )
 )
  )
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline Collector

Re: code for movement keys
« Reply #3 on: July 31, 2014, 06:50:31 PM »
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.
KQII Remake Pic

Offline Cloudee1

Re: code for movement keys
« Reply #4 on: August 01, 2014, 07:59:51 AM »
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.

Code: [Select]
 (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.
« Last Edit: August 01, 2014, 08:04:47 AM by Cloudee1 »
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.04 seconds with 20 queries.