1 (edited by HondaDirtBiker 2006-06-16 02:55:44)

Topic: Reading two buttons at the same time.

I need the event receiver to read two or more buttons at the same time.
I know I post on here alot, and everyone has been great, but i'm still confused by the event receiver. The Irrlicht tutorials only demonstrate pressing one button at a time. So how could my code understand multiple input at the same time, including the GUI?
Thank you.

Global CNT:Int = 0
Global ListBox:T_irrIGUIListBox

Type MyEventReceiver Extends T_irrIEventReceiver

    Method OnEvent:Int(event:T_irrSEvent)

'---------------- Input Events -----------------
        If (event.GetEventType()=EET_KEY_INPUT_EVENT and event.GetKeyPressedDown()=True)
            
            Local Key:Int=event.GetKeyInputKey()
            
            Select Key
            'Thrust
                'Forward
                Case EKEY_UP
'                    thrust:Int = 1
                    Return True
                'Retro
                Case EKEY_DOWN
'                    retro:Int = 1
                    Return True
            
            'Action Primary
                Case EKEY_SPACE
                    Ammo:-1
                    Return True
            
                Default
                    Return False
            EndSelect
        EndIf

'----------------- GUI Events ------------------
        If (event.GetEventType()=EET_GUI_EVENT)

            Local id:Int = event.GetGUIEventCaller().GetID()
            Local GUI:T_irrIGUIEnvironment = device.GetGUIEnvironment()

            Local EvType:Int=event.GetGUIEventType()

            Select EvType
                rem
                If a scrollbar changed its scroll position, And it is 'our'
                scrollbar (the one with id 104), Then we change the
                transparency of all gui elements. This is a very easy task:
                There is a skin Object, in which all color settings are stored.
                We simply go through all colors stored in the skin And change
                their alpha value.
                endrem

                Case EGET_SCROLL_BAR_CHANGED
                    If (id = 104)
                        Local Pos:Int = T_irrIGUIScrollBar.CreateFromHandle(event.GetGUIEventCaller().handle,False).GetPos()
                        Local I:Int

                        For I=0 To EGDC_COUNT-1
                            Local Col:T_irrSColor = GUI.GetSkin().GetColor(I)
                            Col.SetAlpha(Pos)
                            GUI.GetSkin().SetColor(I,Col)
                        Next
                    EndIf

                rem
                If a button was clicked, it could be one of 'our'
                three buttons. If it is the first, we shut down the engine.
                If it is the second, we create a little window with some
                text on it. We also add a String To the list box To Log
                what happened. And If it is the third button, we create
                a file open dialog, And add also this as String To the list box.
                That's all for the event receiver.
                endrem

                Case EGET_BUTTON_CLICKED

                    If (id = 103)
                        device.CloseDevice()
                        Return True
                    EndIf

                    If (id = 102)
                        ListBox.AddItem("Window created")
                        CNT :+ 30
                        If (CNT > 200)
                            CNT = 0
                        EndIf

                        Local Window:T_irrIGUIWindow = GUI.AddWindow( ..
                            T_irrRect_S32.CreateFromVals(100 + CNT, 100 + CNT, 300 + CNT, 200 + CNT), ..
                            False, .. ' modal?
                            "Test window")

                        GUI.AddStaticText("Please close me", ..
                            T_irrRect_S32.CreateFromVals(35,35,140,50), ..
                            True, .. ' border?
                            False, .. ' wordwrap?
                            Window)

                        Return True
                    EndIf

                    If (id = 101)
                        ListBox.AddItem("File open");
                        GUI.AddFileOpenDialog("Please choose a file.")
                        Return True
                    EndIf
            EndSelect
        EndIf

        Return False

    EndMethod

    ' we must override the generate function in order for instantiation to work properly
    ' must return T_irrIEventReceiver
    Function Generate:T_irrIEventReceiver()
        Return T_irrIEventReceiver(New MyEventReceiver)
    EndFunction
EndType

Re: Reading two buttons at the same time.

greetings HondaDirtBiker smile  the default input receiver in Irrlicht is a bit lacking.  i ported a better receiver that does allow checking multiple inputs at once.  its available in the gg.IrrAddons module in the downloads section and is called T_irrSmoothEventReceiver.  use the methods on it to check for input similar to B3D.  you may need to recompile it for BMAX 1.20.

3 (edited by HondaDirtBiker 2006-07-06 12:02:32)

Re: Reading two buttons at the same time.

I tried seting up the "irraddons" and blitzmax could'nt build the module. It says it could'nt find "gg.irraddons" but it is in the right place. I tried the BMK compiler and it compiled "irrlicht" and "irrbmax" but the "irraddons.cpp" did not compile.
What can I do?

Re: Reading two buttons at the same time.

Re: Reading two buttons at the same time.

I'm not sure how to use the smooth event receiver.
When I check a key press nothing is returned.

Here's an example of what I tried.

Strict
Framework brl.Blitz
Import brl.StandardIO
Import irrlicht.Core
Import irrlicht.addons
Import brl.pngloader

Const ScreenW = 800, ScreenH = 600, ScreenD = 32
Global Rcv:SmoothEventReceiver = SmoothEventReceiver.createReceiver()
Global device:IrrlichtDevice = IrrlichtDevice.Create( EDT_DIRECT3D9, _DIMENSION2DI( ScreenW, ScreenH ), ScreenD, True, False, True, Rcv )

While(Device.Run())
UsrIpt()
Wend

Function UsrIpt()
    If Rcv.IsKeyDown( EKEY_KEY_W ) Then Print "W Key Pressed"
End Function

Re: Reading two buttons at the same time.

SuperStrict
Framework brl.Blitz
Import brl.StandardIO
Import irrlicht.Core
Import irrlicht.addons
Import brl.pngloader

Const ScreenW:Int = 800, ScreenH:Int = 600, ScreenD:Int = 32
Global Rcv:SmoothEventReceiver = SmoothEventReceiver.createReceiver()
Global device:IrrlichtDevice = IrrlichtDevice.Create( EDT_DIRECT3D9, _DIMENSION2DI( ScreenW, ScreenH ), ScreenD, False, False, False, Rcv )

While(Device.Run())
UsrIpt()
Wend

Function UsrIpt()
    If Rcv.IsKeyDown( EKEY_KEY_W ) Then Print "W Key Pressed: "+MilliSecs()
End Function

7 (edited by HondaDarrell 2007-04-23 13:21:23)

Re: Reading two buttons at the same time.

I forgot to look at the output. tongue
I was only paying attention to another expression I had added.
Thank you gman.

Re: Reading two buttons at the same time.

glad i could help smile

Re: Reading two buttons at the same time.

For some reason when I use "IsKeyUpDown()", the key reads pressed for longer than a single frame. I need the key to read pressed then ignored by the next frame.
Am I using this command correctly?

Re: Reading two buttons at the same time.

greetings smile  i put out a new addons mod that may fix your problem.  lmk how it goes!

11 (edited by HondaDarrell 2007-04-28 15:02:48)

Re: Reading two buttons at the same time.

I'm still having the same problem.
KeyUpDown updates faster when I lower the system keyboard typomatic delay.
It seems like the key reads UpDown untill the typomatic delay elapses.

Strict
Framework brl.Blitz
Import brl.StandardIO
Import irrlicht.Core
Import irrlicht.addons
Import brl.pngloader

Const ScreenW = 800, ScreenH = 600, ScreenD = 32
Global Rcv:SmoothEventReceiver = SmoothEventReceiver.createReceiver()
Global Device:IrrlichtDevice = IrrlichtDevice.Create( EDT_DIRECT3D9, _DIMENSION2DI( ScreenW, ScreenH ), ScreenD, True, False, True, Rcv )
Global State:String

While( Device.Run())
    UsrIpt()
Wend

Function UsrIpt()
    State = "Working"
    If Rcv.IsKeyUpDown( EKEY_SPACE ) Then State = "You shouldn't be reading this"
    Print State
End Function

Re: Reading two buttons at the same time.

this was a fun one to track down but i think i finally have it.  essentially rendering is happening faster than the key detection so the same keypress in the loop is returning True multiple times.  after much review of the code i just couldnt see how a call to IsKeyUpDown could happen multiple times in a row.  by adding the keyhitcnt to the end of the State i found saw that the count was not increasing per message:

State = "You shouldn't be reading this: "+Rcv.KeyHitCnt(EKEY_SPACE)

the count gets incremented with each key down detection so it remaining at the same # for all the draws means that the same press is being reported.  i think i have resolved your issue by using the key hit count.  try changing your code to:

Function UsrIpt()
    State = "Working"
    If Rcv.IsKeyUpDown( EKEY_SPACE ) And Rcv.KeyHitCnt(EKEY_SPACE,True)=1 Then ..
        State = "You shouldn't be reading this: "+Rcv.KeyHitCnt(EKEY_SPACE)
    Print State
End Function

be sure to backtrack through the messages as now the "you shouldnt" message will only happen one time.  by checking the keyhitcnt and passing true to clear it out and set the count to 0, means that after the first call the If will now fail causing your UpDown only once.

Re: Reading two buttons at the same time.

greetings smile  im happy to say i finally took the time to round out the SmoothEventReceiver type.  its now fully documented, includes mouse inputs, and fixes the updown/downup and count issues.  you can download it in the addons post.  hope it works out for you smile

Re: Reading two buttons at the same time.

Wow, thats great! Every things working perfectly.
Thank you, gman.

Re: Reading two buttons at the same time.

glad i could help smile