moderngl / moderngl-window

A cross platform utility library for ModernGL making window creation and resource loading simple
MIT License
244 stars 57 forks source link

detecting left shift and left ctrl alone #187

Open chriscamacho opened 8 months ago

chriscamacho commented 8 months ago

can't find in self.wnd.keys a code for just these keys on their own

    def key_event(self, key, action, modifiers):
        self.leftSft = False
        self.leftCtr = False
        if action == self.wnd.keys.ACTION_PRESS:
            if key == self.wnd.keys.SPACE:
                # reset all to never dragged
                for s in self.sprites:
                    s.offsetx = 0
                    s.offsety = 0

            # no define for this modifiers = false, false, false
            SHIFT_ONLY = 65505
            CTRL_ONLY = 65507

            if key == SHIFT_ONLY:
                self.leftSft = True
            if key == CTRL_ONLY:
                self.leftCtr = True

I'm concerned if some other backend is in use then these magic numbers will not hold...

einarf commented 8 months ago

As far as I remember the modifiers are all bit fields. You can use bitwise operators to do checks like this.

chriscamacho commented 8 months ago

No only if another key is down, at least with pyglet and Linux

On Wednesday 21 February 2024, Einar Forselv @.***> wrote:

As far as I remember the modifiers are all bit fields. You can use bitwise operators to do checks like this.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.< https://ci4.googleusercontent.com/proxy/m_8ZbNc9O6NHqbv2OZ4HIwh5MuBFFXKj9NUohJY1J_jnT2E0kbT5HX-pYrLC6-Co9QR5dW4yVYXG8Ithdfo8fi94jhMIuIPiqEGhJyRVhVbnWitBTPUGvrWzFHAMhGg7JSZRyNCw0sDzlzqQYvZY6dJcP25wdYSZl-HifcWIo17rI4XDk3d63YP9We-fsxX4L25QqyAzjftsjVGj4PN6KyJ9G34Nxh6_0tjFKCddipG1jIsxtw=s0-d-e1-ft#https://github.com/notifications/beacon/AAFO4SOHSD456YCTJ3TNA33YUVKE7A5CNFSM6AAAAABDKV6T5SWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTUSJHAE.gif>Message ID: @.***>

--

blog bedroomcoders.co.uk http://bedroomcoders.co.uk Free source code and tutorials!

Disclaimer: By sending an email to ANY of my addresses you are agreeing that:

  1. I am by definition, "the intended recipient"

  2. All information in the email is mine to do with as I see fit and make such financial profit, political mileage, or good joke as it lends itself to. In particular, I may quote it where I please.

  3. I may take the contents as representing the views of your company.

  4. This overrides any disclaimer or statement of confidentiality that may be included on your message.

implr commented 2 months ago

I ran into this problem too.

The magic number you're seeing comes from pyglet's keys.py: https://github.com/pyglet/pyglet/blob/master/pyglet/window/key.py#L297 \ The constants in wnd.keys come from moderngl_window/context/pyglet/keys.py in that case, which doesn't forward shift as a standalone key from pyglet's key module.

It'd be fairly straightforward to add that (and I think I'll send a PR soon), but the the issue is that we'd have to do it for all platforms.