Keycodes

This topic contains 13 replies, has 5 voices, and was last updated by  abakobo 1 year, 10 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #8617

    AdamStrange
    Participant

    OK here’s what I want:

    field KeyPress:int

    a variable say KeyPress that equals Key.X

    and can then be redefined

    E.G.

    KeyPress = Key.Z

    #8619

    Jesse
    Participant

    can’t you do this for now?:
    Field keyPress := Key.X
    later
    keyPress = Key.Z

    #8620

    abakobo
    Participant

    Keys are Enums of type Key.

    They are defined in mojo/input/keycodes.monkey2

    you just have to

    [/crayon]

    and then you can (or just do as Jesse wrote)

    [/crayon]

    you may also

    [/crayon]

    But you’ll lose it’s Enums properties (mainly the ability to |Key.Raw in this case, wich sould ALWAYS be used for WASD type controls IMO). And you wont be able to reconvert it to the ‘Key’ type easily.

    If it’s of the ‘Key’ type you’ll be able to
    `keyPressed=keyPressed.Y’
    wich can be usefull if you call your keyPressed just k for example.

    #8655

    AdamStrange
    Participant

    all great but not quite what I was looking for. ;/

    but found a solution:

    using the int allowed me to do what I wanted in the OnMouseEvent

    and (yep using a hidden command – thanks Mark)

    This was I can redefine the keys (properly IMHO) as ints that can come from external sources and controls

    #8657

    abakobo
    Participant

    I don’t really get what you’re trying to do here but I know you don’t have to be warned that hidden functionalities are subject to change..

    #8659

    AdamStrange
    Participant

    thats what I was trying to do:

    a screen where I could change the keybindings

    the controls return the key being winded as an int

    #8661

    abakobo
    Participant

    using the int allowed me to do what I wanted in the OnMouseEvent

    I don’t undestand why you want to mix mouse events and key events… or you meant OnKeyEvent?
    You want the player to be able to chose between mouse or key controls?

    #8662

    AdamStrange
    Participant

    My bad – should have been OnKeyEvent ;[

    It’s a simple rebinding screen. but it’s not simple to actually do it

    #8663

    Jesse
    Participant

    can’t you cast it to an integer? I think that’s what I did to one of my games.

    #8664

    AdamStrange
    Participant

    yep I think that’s what the hidden command is doing as well (casting that is)

    #8679

    impixi
    Participant

    This is the way I’m currently doing it:

    1. Enumerate the in-game commands that are assignable to keys:

    [/crayon]

    2. Store and initialise the keybindings in a global Key array:

    [/crayon]

    3. Check for the bounded keys during the game’s update call:

    [/crayon]

    The hope is it will make it easy to add a key-rebinding screen (as you’re wanting to do)…

    I’ll probably encapsulate the behaviour in a class but the fundamentals are there…

    #8690

    Mark Sibly
    Keymaster

    I like it Impixi. Actually, I’ve been thinking about doing something similar on and off for ages – very ‘top of my head’ code follows…

     

    The basic idea being your code would only really have to deal with GameControllers and GameButtons.

    Possibly a bit ‘high level’ for monkey2? Or not?

    #8724

    impixi
    Participant

    @Mark Sibly:

    Yes, nice idea, and probably the way it “should” be done. 🙂

    Possibly a bit ‘high level’ for monkey2? Or not?

    Not at all: extra functionality is always welcome. But don’t spread yourself too thin: you have enough to do already! 🙂

    #8731

    abakobo
    Participant

    Like impixi, it’s welcome but can be part of 3rd party framework too. You probably have more interresting things to achieve.
    But it would be nice if the KeyboardDevice (and others InputDevices) had a ‘Last(pressed)Button’ method in order to make controls setupscreen without the need of the OnKeyEvent method override (or other On(INPUT)Event)

    I made a little controls setup demo (without the use of ints, only Key) to show it. In the case I missed something.

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.