Little mojox example – calculator

About Monkey 2 Forums Monkey 2 Programming Help Little mojox example – calculator

Tagged: ,

This topic contains 8 replies, has 3 voices, and was last updated by  Simon Armstrong 2 years, 9 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #3254

    degac
    Participant

    Ok, I’m trying to learning MX2 and mojox… so I start to create a simple calculator.

    BUT, I’m locked.

    I haven’t found any ‘gadget event’ handling (like in BlitzMax/MaxGUI), I know I can use ‘actions’ or some function pointer (or what is called), and now I’m stopped :/

    ps: some thing in mojox must be ‘fixed’ I think – like the text alignment in textfield

    The idea was to check what button is pressed.

    if it’s a numeric one (0,1,…9) just add to the result, if is another kind (+,- etc) doing the operation/deleting a char/etc…

    Any help is appreciated 🙂

    #3257

    Simon Armstrong
    Participant

    There are some examples in mojox/bananas, edit hmm folder is actually named tests.

    testbutton.monkey2:

    #3259

    Jesse
    Participant

    interesting! I need to learn how to use Lambda.

    I was trying to get degac’s code to work but run into problems. How do you access keys like the Plus key? I can access the equal key but not the Plus key which is a shift of the same key.

    #3260

    degac
    Participant

    Oh! Thanks!

    I didn’t noticed that folder!

    #3261

    degac
    Participant

    Found a possible solution using Lambda() and a Global ref to txt_result! (this was the problem!)

    Ok, it’s not very ‘beautiful’ code, just written it to test if the logic works.

    Now it’s time to sleep, thanks again!

    #3262

    degac
    Participant

    @Jessi: MMM… I don’t understand your question!

    #3264

    Jesse
    Participant

    I was trying to use the keyboard to control the input for the operations. I used OnKeyEvent and event.Key to access the the keyboard input but Event.Key does not return all the keys pressed. At least not in a way I can comprehend. It seems to me that it returns the keyboard button but not the key. for example on the qwerty keyboard the plus and equals sign are on the same key. so If I want to use the equal sign it’s fine. but if I want to use the plus sign it registers as the equal sign. I am probably missing something but don’t know.

    #3323

    degac
    Participant

    Ok, I understood.

    I still have no explored deep the ‘key’ event, but I’m quite sure the ‘key’ is just the button pressed on the keyboard…

    Looking at the code & manual there’s a field TEXT in the keyevent returned that should have the ‘ascii character’ pressed I suppose!

    I just tested and if I press the ‘1’ key (on the mainboard) I got (many… depends on my pressure) ‘1’.

    If I try to press SHIFT+1 (to print !) I got both SHIF LEFT and 1 …

    I looked and mojo/input has a class KeyboardDevice… it should what needed.

    I have to investigate

    ps: it’s not an ‘error’ of MX2, it’s due to the different keyboard layout (and notebook are different again!)

    #3324

    Simon Armstrong
    Participant

    I think you need to be testing for event type of EventType.KeyChar before using contents of event text.

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

You must be logged in to reply to this topic.