Code Monkey home page Code Monkey logo

Comments (7)

luiz00martins avatar luiz00martins commented on July 17, 2024 1

Not exactly. What I want is to capture a specific key, say ., and move to the next input after ..

However, using this code:

A:onKey(function(self, event, key)
	if key == 46 then
		B:setFocus()
	end
end)

ends up with the dot in B. Again, the problem is not that the output does or doesn't go to A. The problem is that the output goes to B:

Clip.onKey.2.mp4

The output I expected was "This is a sentence." in A, and nothing in B. If the code had a return false, I would expect the output to be "This is a sentence" in A, and nothing in B.

The sleep solution feels... suboptimal. I feel like the output should just not be recasted to B (i.e. instead of outputting to the currently focused object, it should output to the target object of the keypress). More specifically:

  • If return == false, then no output should be produced in either.
  • If return ~= false, then the output should be produced to A, not to B.

from basalt.

NoryiE avatar NoryiE commented on July 17, 2024 1

Hello, thank you very much. I understand now why this is happening. Basalt 1.6.3 has the fix for it - i seperated the char events from the key events, this menas you would need to use a :onChar() event instead of :onKey().

If you are curious on how the events work:
I am using the cc:tweaked event "char" for changing the input. The problem here was the key event always happens before the char event, and i decided one time to call both, the key and the char event when someone uses :onKey(f) which means in your case, you click the ".", the key loop runs, you make the b-input to be the focused one, then the char event loop runs and it writes the . into the b-input (because its focused).

from basalt.

Erb3 avatar Erb3 commented on July 17, 2024 1

Before this gets closed, I would just like to say that you did a awesome job of writing that bug report, and great replies from both of you! ❤️
Keep it up, and thanks for submitting the issue.

from basalt.

NoryiE avatar NoryiE commented on July 17, 2024

Hey! This isn't a bug. :setFocus sets the object immediatley as the focused object. The reason why your custom onKey event handler happens before the inputbox's key event handler is because of the following code:

A:onKey(function(self, event, key)
   if(key==keys.a)then
      return false
   end
end)

this code would make it impossible to write "a" into the inputbox. A possibility would be to create a delayed task:

A:onKey(basalt.schedule(function(self, event, key)
  sleep(0.1)
  B:setFocus()
end)

This code would wait 0.1s before changing the focus.
https://basalt.madefor.cc/#/objects/Basalt/schedule

from basalt.

luiz00martins avatar luiz00martins commented on July 17, 2024

I'd also be fine with the key not being recorded by any of them. My major problem is that the key 'passes over' to B.

Is there a way to avoid that?

from basalt.

NoryiE avatar NoryiE commented on July 17, 2024
A:onKey(function(self, event, key)
  B:setFocus()
  return false
end)

This would make it impossible to write into the input "A" - i am not sure if that's what you want.

from basalt.

luiz00martins avatar luiz00martins commented on July 17, 2024

Just checked. Everything is working as intended now!

Thank you for the quick fix, and thank you for the compliment! I'm using basalt for a personal project, so expect to hear from me again! Cheers

from basalt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.