User Input with Text Field or Text Box

Discussion in 'Programming' started by atxgamedesigner, Jun 25, 2016.

  1. Hello,

    I'm working on a small desktop application and would like to integrate user input through a text field / text box.

    Specifically, I'd love to have a large text box - something like notepad.
    A multi-line input area for text, where the string will wrap on to the next line once it reaches the edge of the box.
    Honestly, I'm not sure how to achieve this.

    I feel that I have a fairly solid understanding of how to display and manipulate strings with GML, but this is really taking that knowledge to the next level.
    I was considering buying one of the extensions from the marketplace, but decided that I would rather benefit from the gained knowledge in doing it myself (as well as customizing it to fit within my application from the beginning).

    If anyone can help point me in the direction of more information on this topic, or perhaps share some conceptual ideas of how this might work, it would be greatly appreciated.

    Thanks for your time!
  2. Aura

    Aura Guest

    atxgamedesigner likes this.
  3. Hi Aura,

    Thanks for the reply.
    This isn't quite what I'm looking for, but its a good place to start - thanks for sharing the link.

    Anyone else have some ideas?
  4. Edeyz

    Edeyz Member

    Sep 23, 2016
  5. Tthecreator

    Tthecreator Your Creator!

    Jun 20, 2016
  6. IzzieBlu

    IzzieBlu Member

    Apr 6, 2017
    I know I'm super late but this is for people in the future who are in need of help.

    Create Event:
    /// Variables
    cursorPos = 1 // The position of the caret
    inputText = "" // The input line of text
    Step Event:
    /// Input
    // Variables
    var ctext = ""
    // Clipboard
    if(keyboard_check(vk_control) && keyboard_check(ord("V")) && clipboard_has_text())
    { ctext = clipboard_get_text() }
    if(ctext!="" && (keyboard_check_pressed(ord("V")) || keyboard_check_pressed(vk_control)))
    { inputText = string_insert(ctext, inputText, cursorPos) }
    // Backspace
          inputText = string_delete(inputText, cursorPos-1, 1)
          inputTimer = inputWait
    if(keyboard_string != "")
          var t = keyboard_string;
          inputText = string_insert(t, inputText, cursorPos)
          keyboard_string = ""
    // Cursor
    if(keyboard_check_pressed(vk_left)){ cursorPos-=1 }
    if(keyboard_check_pressed(vk_right)){ cursorPos+=1 }
    Wherever You're Using the Input Text:
    /// Display Text
    // Add the caret into the input text
    displayText = string_insert("|", inputText, cursorPos)
    // Ex. draw_text(10, 10, displayText)
    This is simple enough to work but may need some fiddling if you want numpad keys, some special keys or keys like home, end, insert and delete to work or even making the cursor go to the mouse position. However this does work with clipboard pasteing, typing and backspacing.
    Some stuff that will make it look or feel better: blinking caret, backspace having a timer, selecting, mouse click positioning. All of those aren't too hard to implement so consider them.

    Hope this helps!
    Last edited: Mar 10, 2018
  7. Deklaration

    Deklaration Member

    Mar 7, 2018
    Hi, sorry. I've been at this forever and the code you posted is kind of similar to how I write my code. I'm very happy to find some help I can understand.
    However, I don't really understand
    Where should I put this line? I've tried several options and have yet to see any text. If you could explain a bit more just that part, I would be very grateful. I just need some kind of notepad application in my game.

    EDIT: Sorry, just figured it out. Thanks for the help!
    Last edited: Mar 7, 2018
    IzzieBlu likes this.
  8. Kezarus

    Kezarus Member

    Jan 14, 2018
    Well, I'm gonna try to use this today and see how this plays out. Thanks Izzie! =]

    I love Game Maker, but this lack os UI elements drags my dev speed down... Lost a day in drag and drop already... =/

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice