简体   繁体   English

无法使用 OpenFL Legacy Cpp Build 在 TextField 中使用 Ctrl+V

[英]Cannot Ctrl+V in TextField with OpenFL Legacy Cpp Build

I am currently working on an application using the HaxeUI library.我目前正在使用 HaxeUI 库开发一个应用程序。 In my application, I am creating TextInput objects, which are based off of OpenFL's TextField .在我的应用程序中,我正在创建基于 OpenFL 的TextField TextInput对象。 Unfortunately, when compiling for Windows or Neko, these fields do not allow for basic faculties like Ctrl + V , Ctrl + C , or Ctrl + A .不幸的是,在为 Windows 或 Neko 编译时,这些字段不允许使用Ctrl + VCtrl + CCtrl + 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.结果,我觉得我可以自己扩展TextInput类,它只使用KeyboardEvent.KEY_DOWN事件来检测这些特定功能。 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!"看起来如果我按Ctrl然后按V ,它应该打印出"CTRL PRESSED!" and "PASTE!""PASTE!" . . However, I only ever get "CTRL PRESSED!"但是,我只得到"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.事实上,经过一番激烈的测试,我发现如果按住 Ctrl按钮,那么除了AltShift键之外, KeyboardEvent.KEY_DOWN不会注册任何其他按键。 In other words, detecting Ctrl and V being held simultaneously is impossible unless V is pressed first;换句话说,除非先按下V,否则无法检测到同时按住 CtrlV however, since conventionally Ctrl is pressed first, this doesn't work for me.但是,由于通常先按下Ctrl ,因此这对我不起作用。

Is there a way I can register actions like Ctrl + V in a TextField in OpenFL for Windows?有没有办法可以在 OpenFL for Windows 的TextField中注册诸如Ctrl + V 之类的操作? Or at least, is there a way I can detect the sequential key presses of Ctrl , followed by V ?或者至少,有没有一种方法可以检测Ctrl的连续按键按下,然后是V I've tried having Ctrl on KEY_DOWN and V on KEY_UP , but it is not responsive enough for practical use.我试过在KEY_DOWN上使用Ctrl ,在KEY_UP上使用V ,但它的响应不够实际使用。

I am using OpenFL 3.6.0, Lime 2.9.0, and HaxeUI 1.8.17.我使用的是 OpenFL 3.6.0、Lime 2.9.0 和 HaxeUI 1.8.17。 It should be noted that HaxeUI requires OpenFL Legacy.需要注意的是,HaxeUI 需要 OpenFL Legacy。 In non-legacy OpenFL, I was able to get Ctrl + V working just fine.在非传统 OpenFL 中,我能够让Ctrl + V正常工作。

This is why they made OpenFL next.这就是他们接下来制作 OpenFL 的原因。 I'm not sure if it's not possible or not easy to detect those keypresses in legacy, but I highly doubt that functionality would be added at this point since you got it to work with next.我不确定在旧版中检测这些按键是否不可能或不容易,但我非常怀疑此时会添加功能,因为您接下来要使用它。

So it's kind of a "Will OpenFL add to their legacy codebase?"所以这有点像“OpenFL 会添加到他们的遗留代码库中吗?” versus "When does the next major version of HaxeUI come out?"“HaxeUI 的下一个主要版本什么时候出来?” There are enough issues with TextFields on next that they're probably not going to also fix legacy's longstanding problems.接下来的 TextFields 有足够多的问题,它们可能不会也解决遗留的长期问题。 And a new HaxeUI is coming eventually.一个新的 HaxeUI 最终会到来。

So... no you can't.所以……不,你不能。 Not yet.还没有。

After some thinking about it, I came to realize the lack of responsiveness when using KEY_UP as a workaround was the result of releasing CTRL before V. In normal applications, this is possible because the paste action happens upon key down.经过一番思考后,我意识到在使用 KEY_UP 作为解决方法时缺乏响应是在 V 之前释放 CTRL 的结果。在正常应用程序中,这是可能的,因为粘贴操作发生在按下键时。

To get around this, I simply applied a delay on the release of CTRL:为了解决这个问题,我只是延迟了 CTRL 的释放:

class SmartTextInput extends TextInput {
    public function new() {
        super();
        ctrlDown = false;
        this.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
        this.addEventListener(KeyboardEvent.KEY_UP, keyUp);
    }

    private static inline var CTRL_SENSITIVITY = 100;
    private var ctrlDown:Bool;

    private function keyDown(e:KeyboardEvent):Void {
        if (e.keyCode == Keyboard.CONTROL || e.keyCode == Keyboard.COMMAND)
            ctrlDown = true;
    }

    private function keyUp(e:KeyboardEvent):Void {
        if (e.keyCode == Keyboard.CONTROL || e.keyCode == Keyboard.COMMAND)
        //  The delay here is for people who release control before releasing the letter key
            Timer.delay(function() {  ctrlDown = false; }, CTRL_SENSITIVITY);
        if (ctrlDown) {
            switch(e.keyCode) {
                case Keyboard.C: copy();
                case Keyboard.V: paste();
            }
        }
    }
}

Though not optimal, this is seems to work well enough.虽然不是最优的,但这似乎工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM