Keypress events?

juncmodule A while back Lars and Chris posted this:

http://www.mega-tokyo.com/forum/index.php?board=5;action=display;threadid=576

I am going to try to use the evKeyboard to do this:

player presses F6 (this is already mapped in the menu_bar) and ego draws a sword (change view). Player holds shift(change view) and presses the arrow forward key, ego stabs with sword(changes to next forward cell of view). Player releases shift (change view) and walks around, ego walks around with sword drawn until F6 is pressed again or until shift key is held and he stabs stuff.

Now of course, I am making this harder than it needs to be. I could just use F6 to change the view so that when you press forward he stabs. I think that would limit the gameplay though.

Has anyone ever done anything like this?
Does anyone know if evKeyboard will in fact handle all of this?
Does anyone have any recommendations as to another way to do it?

Thanks,
-junc
Lars Skovlund The shift keys (and various others) don't generate keyboard events. Rather, their state is implicit in any Event object.
In other words, look at the 'modifiers' properry of every incoming event, not just unclaimed keyboard events. You will want
to modify User:handleEvent to handle this as early as possible,
since the class hierarchy discards null events by default.

Lars
juncmodule Thanks Lars. I think I'm going to take a step back from my game and work on other features.

I just don't get it :P.

I do understand how to assign actions through the menu bar. So, I will just use that, release a demo, ask for help then.

Thanks again for your help.
-junc
fck I hope this will help you. You cannot use Shift on it own, but that should not be a problem. Use can use any other key or a Ctrl-key sequence. I would steer away from Fn buttons and be careful of some Ctrl sequences. I had eq. a reboot when I used F6.

Here is a somewhat verbose explanation in a tutor format:

INTERCEPTING KEYBOARD AND MOUSE EVENTS

For this demonstration, Ego will change into Brian if the player presses B (capital) and back to Ego when E (capital) is pressed.

Add Brian as a view as described in the Tutorial Chapter 19 (Resource->Add Sample->View->Brian and save it as view number 1.

In the instance of RoomScript add the following code:

(instance RoomScript of Script
(properties)
(method (handleEvent pEvent)
(var str) //Local variable
(super:handleEvent(pEvent))

.
.
(switch( (send pEvent:type) )
(case evKEYBOARD
(if(== (send pEvent:message) KEY_B ) //Check if B was pressed
(send gEgo:view(1)) //switch to Brian
(send pEvent:claimed(TRUE))
)//if B

(if(== (send pEvent:message) KEY_E ) //Check if B was pressed
(send gEgo:view(0)) //switch to Ego
(send pEvent:claimed(TRUE))
)//if
)//evKEYBOARD

//For fun intercept the Mouse event as well
(case evMOUSEBUTTON
(Print("You pressed a Mouse Button!"))
)//evMOUSEBUTTON
)//switch
)//method
)//instance


The code: send pEvent:claimed(TRUE)): specified whether the event object can be used; in this case the :Said: command will ignore the event when the player presses either a B or E.

Compile and test. Ego will be transformed into Brian if you press a B and back to Ego if you press an E. If it does not work, the values may not be declared in the Keys.sh file. Open the file (..\SciStudio\include\Keys.sh) to view the defined values. You may want to expand the list with the lower case values (a=$61,..z=7a). If you want to trap other values, you can view the value of the key code by adding the following code just below the :case evKEYBOARD: statement:


=str ""
(Format(str "str=%x" (send pEvent:message)))
(Print(str))


Test by pressing Ctrl-k. The value should be $0b. You can add the value in the Keys.sh file or using it directly in the statement (if(== (send pEvent:message) $0b) ext