How to capture keystroke usage in a ListView

Hi, I'm building a script to edit audio file metadata, and I'd like to delete the selected files when I select files in the listView and press the Delete key. I've tried this, but the Delete key press isn't recognized.

while (true) {
    var msg = dlg.GetMsg();
    if (!msg.result) break;

    // Trying to detect Delete key press when ListView has focus
    if (msg.event === "keydown" && msg.control === "listview1") {
        DOpus.Output("Key pressed on control: " + msg.control + " | Keycode: " + msg.keycode + " | Key: " + msg.key);

        if (msg.key === "delete" || msg.keycode === 46) {
            limpiarLista(dlg);
            continue;
        }
    }
}

There is no event called "keydown"

Here's how to register hotkeys in a dialog using the AddHotkey() method :

Usually, AI tends to "hallucinate" when asked for this type of tasks, which are not "mainstream" (and in fact, I think it does the same thing in everything related to coding.)

1 Like

Thanks so much @errante, thanks to your links I learned a little more about events and AddHotkey() today. I ended up getting the result I wanted in the following way:

 dlg.AddHotkey("limpiar", "delete");

 dlg.Show();

 while (true) {
     msg = dlg.GetMsg();
     if (!msg.result) break;

     if (msg.event === "hotkey") {
         if (msg.name === "limpiar") {
             limpiarLista(dlg);
         }
     }
1 Like

We'll add a way to detect keypresses in listviews directly in the next update.

4 Likes