Is there a way to prevent TAB from jumping around the browser window?

0 favourites
  • 9 posts
From the Asset Store
Get Ready for the New Wave of "Bottom Screen" Games!
  • So I'm making a code editor for my 6502 Emulator, and obviously indenting is a big part of keeping code clean and readable... I would like to use TAB for this, as obviously that's the key used in every other text/coding app ever... There must be a way to do that in a C3 app, no?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • With the text input object hitting tab jumps between edit controls. You’ll need a bit of JavaScript to change that.

    Give the textInput object an id of “edit” in the properties bar. Then run a script like this once to change it so that so tab does nothing.

    document.getElementById("edit").addEventListener("keydown", (e)=>{if(e.key=="Tab"){e.preventDefault()}});

    From that you can make it do something else such as place four spaces or something. The easiest way would be to call a c3 function from that js to do the text modification there. Construct’s docs have how to do that.

  • I'm currently using SpriteFonts inside of my own "focused" panel to manually accept the keybaord input, as the keypresses are being directly translated into their ascii byte data sent to a binaryData object, which is then being parsed and displayed by the SpriteFont... I can't say I see anywhere to give an id to SpriteFont, perhaps under the "tags" section?

  • Part of the goal if this editor is to be able to save and load external files that will work and behave correctly inside of other editors as well. Primarily Notepad++.

  • Ah. Well if you’re just getting the key pressed from the keyboard object you can forget about that JavaScript.

    Just add a tab character to the spritefont, set its width, and you’re good to go. You’ll probably have to type tab in something like notepad and copy/paste it over unless construct supports escaped characters like \t.

  • I'm not sure I understand what how a "TAB" character in the SpriteFont with a custom width would work... It's also the pressing of the Tab key that's the issue... I can already send the ascii byte code for Tab to the binaryData, and when it gets retrieved as Text, it works properly, the issue is that I can't seem to use the Tab key to send that byte data... it works fine if I wire it to a different key

  • Well, if you modify that js snippet to add the event listener to the document instead of a textInput control then it will keep the tab key from jumping around the browser window.

    This is what I mean by what I said about letting you type with the tab key in a spritefont.

    dropbox.com/scl/fi/1392o042wut3fuzj6vik5/SpritefontTextInput.c3p

  • Ok... this is sick. Can we be friends? lol

  • Also, this seems like it'd be a useful Keyboard Object Property. Just to have a little checkbox somewhere to toggle "TAB Default Behaviour" or something.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)