Coder Social home page Coder Social logo

Comments (4)

floooh avatar floooh commented on August 24, 2024

The main difference is that CHAR gives you the UNICODE code point of what's printed on the keyboard key (assuming correct keyboard layout settings in the OS), while the KEY events are "virtual key codes" which are independent from any international keyboard layout.

E.g. for text input you would use CHAR events, and for game controls you would use KEY events.

What do you mean with "behaves like text inputs" for KEY events, the key repeat?

If you're just interested in whether a key is currently held down, you need to track that yourself. For example see here in pacman.c:

https://github.com/floooh/pacman.c/blob/090c18849c49fb162c27afb0b959bd9fda885f0c/pacman.c#L770-L800

...eventually there might be a separate header which provides such a polling API on top of input events, but that's quite low on the priority stack.

from sokol.

elvodqa avatar elvodqa commented on August 24, 2024

Thank you for the response. Following the pacman.c example, It worked smoothly. What I meant by behave like text inputs is a delay after the first key tick If you are holding down the key. Like: a__aaaaaaaaa.

Too bad I have to keep the state of every key I wanted but It is what it is.

Other than that, are there possible SDL/Sokol usage examples out there, If you are aware? I found a lot of examples for OpenGL but the main reason I'm using Sokol is DXD11 and Metal support.

from sokol.

floooh avatar floooh commented on August 24, 2024

is a delay after the first key tick If you are holding down the key. Like: a__aaaaaaaaa.

Ah right, yeah that might be a bit confusing for "raw" key input, but that's how the underlying operating system events behave. There's a bool key_repeat field in the event struct which you can use to detect and ignore such followup events if desired:

sokol/sokol_app.h

Line 1413 in 17b399b

bool key_repeat; // true if this is a key-repeat event, valid in KEY_UP, KEY_DOWN and CHAR

Closing this ticket if that's ok :)

from sokol.

floooh avatar floooh commented on August 24, 2024

PS:

Other than that, are there possible SDL/Sokol usage examples out there,

Not that I know of unfortunately. The sokol-samples have examples for GLFW+GL (https://github.com/floooh/sokol-samples/tree/master/glfw) plus a very simple example for GLFW+Metal (https://github.com/floooh/sokol-samples/blob/master/glfw/metal-glfw.m).

I haven't attempted to use SDL with sokol_gfx.h so far though.

from sokol.

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.