admin 管理员组

文章数量: 1086019

I'm trying to make a text editor in C for windows (11) using ncurses, as far as i can tell I've gotten every other input working but ctrl+v still pastes from the clipboard.

i already have raw and nonl active, and testing the other ctrl+key combinations give the expected results

#include <ncurses/curses.h>

void enableRawMode() {
    raw();
    nonl();
    noecho();
}

int main(void)
{
    initscr();
    enableRawMode();
    keypad(stdscr, TRUE);
    timeout(10);
    
    int c;
    while (c != 27){
        c = wgetch(stdscr);
        if (c == ERR) {continue;}
        erase();
        move(0, 0);
        wprintw(stdscr, "escape or ctrl+[ to exit");
        move(2, 0);
        if (c < 255) {wprintw(stdscr, "%c (%d)", c, c);}
        else {wprintw(stdscr, "%d", c);}
        refresh();
    }

    endwin();

    return 0;
}

Is there any way of doing this in ncurses? or is this an issue with windows?

I'm trying to make a text editor in C for windows (11) using ncurses, as far as i can tell I've gotten every other input working but ctrl+v still pastes from the clipboard.

i already have raw and nonl active, and testing the other ctrl+key combinations give the expected results

#include <ncurses/curses.h>

void enableRawMode() {
    raw();
    nonl();
    noecho();
}

int main(void)
{
    initscr();
    enableRawMode();
    keypad(stdscr, TRUE);
    timeout(10);
    
    int c;
    while (c != 27){
        c = wgetch(stdscr);
        if (c == ERR) {continue;}
        erase();
        move(0, 0);
        wprintw(stdscr, "escape or ctrl+[ to exit");
        move(2, 0);
        if (c < 255) {wprintw(stdscr, "%c (%d)", c, c);}
        else {wprintw(stdscr, "%d", c);}
        refresh();
    }

    endwin();

    return 0;
}

Is there any way of doing this in ncurses? or is this an issue with windows?

Share Improve this question edited Mar 31 at 21:48 Teeth asked Mar 30 at 3:38 TeethTeeth 514 bronze badges 4
  • It might be. NCurses only has access to the key codes it gets. If something else (like your terminal emulator or the OS window manager) is grabbing a specific key combination then you will never see it. That said, I have never had any difficulty getting Ctrl-V with NCurses on either Windows or Linux. – Dúthomhas Commented Mar 30 at 4:28
  • Quick thought, though: check that “Quick Edit” is disabled in the Windows Console preferences. – Dúthomhas Commented Mar 30 at 4:37
  • @Dúthomhas you were right about the terminal emulator being the issue, ctrl+v was bound to paste under Settings > Actions. deleting that shortcut fixed the issue – Teeth Commented Mar 30 at 5:35
  • Ah, yes, I had fotten that the new Windows Terminal did that! (I’m using Linux for my home PC these days.) – Dúthomhas Commented Mar 30 at 5:43
Add a comment  | 

1 Answer 1

Reset to default 3

This is, in fact, a problem with windows.

More specifically, the default windows terminal emulator has ctrl+v bound to paste by default.

To fix this, click the dropdown arrow at the top of the window, open settings, and remove the shortcut under the 'Actions' section.

本文标签: cHow to return ctrlv with ncursesStack Overflow