Skip to content

Instantly share code, notes, and snippets.

@T1mL3arn
Last active June 10, 2026 08:24
Show Gist options
  • Select an option

  • Save T1mL3arn/7b8e1a5ab3241d1ad9014a277d2b1362 to your computer and use it in GitHub Desktop.

Select an option

Save T1mL3arn/7b8e1a5ab3241d1ad9014a277d2b1362 to your computer and use it in GitHub Desktop.
ceramic any key just pressed component
/**
* This should be class to check if any key is just pressed.
* There is a little bug, but lets see if anyone complains.
*
* To reproduce bug:
* - hold any key
* - press any other key
*
* expected:
* - event triggers
*
* actuall:
* - nothing happens
*/
class AnyKeyJustPressed {
public var anyKeyJustPressed:ceramic.Key -> Void = null;
var input:ceramic.Input.Input;
var prevPressed:Bool = false;
var currPressed:Bool = false;
public function new(?handler:ceramic.Key -> Void, ?input:ceramic.Input.Input) {
anyKeyJustPressed = handler;
this.input = input != null ? input : ceramic.App.app.input;
this.input.onceKeyDown(null, keyDownHandler);
this.input.onceKeyUp(null, reattach);
}
function keyDownHandler(e:ceramic.Key) {
if (anyKeyJustPressed != null)
anyKeyJustPressed(e);
}
function reattach(e) {
input.onceKeyDown(null, keyDownHandler);
input.onceKeyUp(null, reattach);
}
public function destroy() {
input.offKeyDown(keyDownHandler);
input.offKeyUp(reattach);
input = null;
anyKeyJustPressed = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment