Keyboard input handling everywhere....

BlitzMax Forums/BlitzMax Beginners Area/Keyboard input handling everywhere....

Takis76(Posted 2012) [#1]
Hello again,

I would like to , if is it possible to have keyboard handling
everywhere.

What I mean.

When my program starts , the main canvas gadget that I have draws, all the graphics.

I would like to have keyboard input handling everywhere , with maxgui you can capture the keyboard with events.

If EventID() = EVENT_KEYDOWN Then
  If EventSource() = graphics_canvas
    If EventData() = KEY_DOWN
      End
    EndIf
  EndIf
EndIf


The above code captures the keydown event and if I press down arrow then the program ends.
But to capture the keyboard handle , I need to click on the graphics_canvas (Something like giving a focus or select or activate the graphics_canvas and then I can capture my down arrow key.

Is it possible to have keyboard handling to any key without need to take any event from maxgui or without need to press or click on the canvas to be activated first and then capture the keyboard.

Like keydown() function or keyhit() function , but these functions not working now. Are trapped by maxGui

If I need to click my only one canvas I have the "graphics_canvas" how can I always have this canvas activated?

I don't know how to describe my problem.
In few words , to have keyboard handling everywhere without need to click to any gadget to give the event to MaxGUI. Just putting the keydown() or keyhit() function in the main loop , is not working.

Thank you :)

Last edited 2012


Takis76(Posted 2012) [#2]
To help you a little , I have my updated version of my editor uploaded
Here:

https://www.box.com/s/a11341df974ddc61da83


When you start you will see 2 arrows , one Green and one Blue.

The Blue arrow is the party entry in the adventure.
The Green arrow is the camera view.

When you are pressing arrow keys you will move the Green Arrow in the map and you will see on the 3D view to the right of the map.
The Green Arrow is the camera position in the map.

When changing levels the camera follows the level but the BLue arrow remains on the level.

Up arrow - Key 8: move forward
Down arrow - Key 2: move backwards
Left arrow - Key 4: move a side step to the left (strife)
Right arrow - Key 6: move a side step to the right (strife)
Home - Key 7: Rotates the camera to the left
PgUP - Key 9: Rotates the camera to the right

I want the keyboard handing to move this arrow and the player will see how the dungeon is and can travel and see the adventure which will create and then the editor saves the adventure to a playable game which loads from the main game.


Zeke(Posted 2012) [#3]
Add command:
[bbcode]
EnablePolledInput()
[/bbcode]
before mainloop.

and this to your event handling code:
[bbcode]
Case EVENT_APPRESUME
ActivateGadget(canvas)
[/bbcode]
^^ then you can use Keydown() or KeyHit() commands.

and small example:



Takis76(Posted 2012) [#4]
I thing I solved my problem.

I put in the main loop

ActivateGadget graphics_canvas

I will make my experiment and if I have problem I will report.


Takis76(Posted 2012) [#5]
Ok , It worked , I have uploaded the new version:

https://www.box.com/s/a11341df974ddc61da83

I have a new question , when you travel in the map , and you approaching the edge of the map view area , how is it possible to make my map scrolls automatically?

I am trying to find some idea how to make my scroll bars moves when the Green arrow passes the center of the viewed map.

Or I will put one button to center the map with the position of the Green arrow.


My scrollers created with this code


map_horizontal_scroller = CreateSlider(10, 457, 590, 18, graphics_canvas, SLIDER_HORIZONTAL)
SetSliderRange(map_horizontal_scroller, 1, 19)
	
map_vertical_scroller = CreateSlider(602, 80, 16, 374, graphics_canvas, SLIDER_VERTICAL)
SetSliderRange(map_vertical_scroller, 1, 28)




SetSliderValue(map_vertical_scroller,vvalue) sets a new value in scrollbars , how to calculate at least to have the map view centered with the Green arrow?

But if the arrow if is at the edge of the map the scrollers will not exceeds the slider range.

:)


Takis76(Posted 2012) [#6]
When I make the camera centering code and autoscrolling code , I will upload the next version which I found one bug and I fixed it , I used to press KEY6 , KEY4 , KEY8 and KEY2 for moving the arrow , but it was wrong and must be KEY_NUM6 , KEY_NUM4 , KEY_NUM8 and KEY_NUM2.


Zeke(Posted 2012) [#7]
autoscroll (Map_Panel.bmx):



Takis76(Posted 2012) [#8]
I made it. Updated version

https://www.box.com/s/a11341df974ddc61da83


Takis76(Posted 2012) [#9]
I didn't see your new post , I made it with different code , but I will try and your code.

In my version I center the screen to camera position , the camera not scrolls the bars automatically yet.


Zeke(Posted 2012) [#10]
autoscroll v2:



Takis76(Posted 2012) [#11]
Your code was excellent , I use it.


Takis76(Posted 2012) [#12]
I am very happy for now.

I have fixed some bugs and I add few functions to the level editor.

Now the editor save some adventure , only the walls and the party entry in the dungeon.

The game engine loads the adventure as well.

I have one small demo to download.

Create one wall map only with my brand new editor , and run it from the game.

The small demo is here:

https://www.box.com/s/99c823d46963aa2e6b67