zero01101 / openOutpaint

local offline javascript and html canvas outpainting gizmo for stable diffusion webUI API 🐠
MIT License
507 stars 44 forks source link

[Bug]: Repeated keyboard shortcuts ignored #292

Closed Metachs closed 2 months ago

Metachs commented 2 months ago

What happened?

Keyboards shortcuts will eventually stop working when the same key is pressed repeatedly. and will only work reliably if there is a ~1 second delay between keypresses.

This is only noticeable when using Left/Right keys to switch between images, repeatedly press the right key several times a second and eventually it will stop switching,

This appears to be at least indirectly caused by some apparently broken keyhold code in input.js. https://github.com/zero01101/openOutpaint/blob/main/js/lib/input.js#L584

        _hold_to: setTimeout(() => {
            keyboard.keys[evn.code].held = true;
            delete keyboard.keys[evn.code]._hold_to;
            // onkeyholdstart event
            keyboard.listen.onkeyholdstart.emit({
                target: evn.target,
                code: evn.code,
                key: evn.key,
                evn,
            });
        }, inputConfig.keyboardHoldTiming),

Not sure what this is supposed to be doing, but it looks like all it does is set an additional timeout every frame a key is held, each of which emits 'onkeyholdstart', even if the key is no longer held. AFAICT onkeyholdstart/end are unused, and removing the block of code above fixes the ignored keypress issue completely for me.

Steps to reproduce the problem

Repeatedly press the right key with some batched images and eventually it will stop switching,

What should have happened?

Something instead of nothing.

Commit where the problem happens

latest

What platforms do you use to access openOutpaint?

Windows

What browsers do you use to access the UI ?

Google Chrome, Microsoft Edge

Browser Extensions/Addons

None

AUTOMATIC1111 webUI Commandline Arguments

Irrelevant

Additional information

No response

seijihariki commented 2 months ago

Thank you for the report!

Not sure what this is supposed to be doing, but it looks like all it does is set an additional timeout every frame a key is held, each of which emits 'onkeyholdstart', even if the key is no longer held. AFAICT onkeyholdstart/end are unused, and removing the block of code above fixes the ignored keypress issue completely for me.

This code is actually some feature creep in the input library so we can easily detect start/end of held keys (not really used for now I think). While not used for now, I will keep it in the code. I have addressed the issue by properly clearing the timeouts on keyup.

I would be glad if you could test openOutpaint using the branch seijihariki/issue292 to verify if the issue is solved!

Metachs commented 2 months ago

Yup, that fixed it.

zero01101 commented 2 months ago

merged into main, as always many thanks @seijihariki :)