Cannot Ctrl+V in TextField with OpenFL Legacy Cpp Build

I am currently working on an application using the HaxeUI library. In my application, I am creating TextInput objects, which are based off of OpenFL’s TextField. Unfortunately, when compiling for Windows or Neko, these fields do not allow for basic faculties like Ctrl+V, Ctrl+C, or Ctrl+A.

As a result, I felt that I could just make my own extension of the TextInput class which simply uses the KeyboardEvent.KEY_DOWN event to detect these particular functions. The below is a relevant snippet of my implementation:

class SmartTextInput extends TextInput {
    public function new() {
        super();
        this.addEventListener(KeyboardEvent.KEY_DOWN, performPress);
    }

    private function performPress(e:KeyboardEvent):Void {
        if(e.ctrlKey) {
            trace("CTRL PRESSED!");
            switch(e.keyCode) {
                case Keyboard.V: trace("PASTE!");
            }
        }
    }
}

It looks like if I press Ctrl and then V, it should print out “CTRL PRESSED!” and “PASTE!”. However, I only ever get “CTRL PRESSED!”, so it doesn’t work. In fact, after some vigorous testing, I found that if
the CTRL button is being held, then KeyboardEvent.KEY_DOWN will not register any other keypress except the ALT and SHIFT keys. In other words, detecting Ctrl and V being held simultaneously is impossible unless V is pressed first; however, sinceconventionally Ctrl is pressed first, this doesn’t work for me.

Is there a way I can register actions like Ctrl+V in a TextField in OpenFL for Windows? Or at least, is there a way I can detect the sequential key presses of Ctrl, followed by V? I’ve tried having Ctrl on KEY_DOWN and V on KEY_UP, but it is not responsive enough for practical use.

I am using OpenFL 3.6.0, Lime 2.9.0, and HaxeUI 1.8.17. It should be noted that HaxeUI requires OpenFL Legacy. In non-legacy OpenFL, I was able to get Ctrl+V working just fine.

I don’t know about your KeyboardEvent issue in Legacy.

But in Legacy, accessing the system clipboard for native targets was not possible. I needed that functionality for my game, but it turned out that I would have to switch to Next due to lack of support. I think the issue is because the version of Lime or one of the submodules used by Legacy simply does not have the API to access the system clipboard.

It sounds like that’s the functionality you want to implement in your application. Unfortunately I don’t think it’s possible at this time :frowning:

Thankfully, I was able to access the clipboard using the systools library. The real problem was that TextField was not allowing Ctrl actions as is customary. Plus, for some reason, holding the Ctrl button would block the input of all other keys.

I did manage a workaround very recently by having Ctrl on KEY_DOWN and V on KEY_UP. It turns out the lack of responsiveness I mentioned in the original post was due to releasing the Ctrl button before releasing V. Under normal circumstances, the action occurs when V is pressed, not released, and therefore it is possible for the action to complete even if Ctrl is released first. However, when V is changed to KEY_UP, the circumstances change. I got around the issue by implementing a delay on the release of Ctrl.

I posted my code to the workaround on stack overflow, but was curious on if anyone was familiar with the KeyboardEvent issue. Thanks for your input!

Nicely done! I had looked briefly for some lib I could use back then to implement the clipboard access, but didn’t find systools.

Anyway, about the Ctrl issue, I don’t know. It might have been something that was never fully implemented in Legacy, but that sounds odd because it had been around for quite a while, and “Ctrl+something” sounds like a common enough pattern to have been implemented.