static int translate_key_code(int asc, int scan)
{
    int c;
    switch(scan){
    case 106: /* KP_MULT*/
	return ALT('*');
    case 107: /* KP_PLUS*/
	return ALT('+');
    case 109: /* KP_MINUS*/
	return ALT('-');
    }
    c = VKtoCurses (scan);
    if (!asc && !c)
	return 0;
    if (asc && c)
	return c;
    if (!asc || asc=='\t' )
    {
	if (shift_pressed() && (c >= KEY_F(1)) && (c <= KEY_F(10)))
	    c += 10;
	if (alt_pressed() && (c >= KEY_F(1)) && (c <= KEY_F(2)))
	    c += 10;
	if (alt_pressed() && (c == KEY_F(7)))
	    c = ALT('?');
 	if (asc == '\t'){
 		if(ctrl_pressed())c = ALT('\t');
 		else c=asc;
 	}
	return c;
    }
    if (ctrl_pressed())
	return XCTRL(asc);
    if (alt_pressed())
	return ALT(asc);
    if (asc == 13)
	return 10;
    return asc;
}
Example #2
0
inline void Console::handle_input (HANDLE in, ConsoleScreenBuffer & buffer) {

    DWORD num;
    INPUT_RECORD ir;
    if (!ReadConsoleInputW(
                in,
                &ir,
                1,
                &num
            )) Raise();

    //	Nothing was read
    if (num==0) return;

    //	If a resize event was read,
    //	handle and return
    if (ir.EventType==WINDOW_BUFFER_SIZE_EVENT) {

        buffer.Resize();

        return;

    }

    //	We're only concerned with key
    //	press events besides resize
    //	events
    if (!(
                (ir.EventType==KEY_EVENT) &&
                (ir.Event.KeyEvent.bKeyDown)
            )) return;

    //	Loop for the number of times
    //	this key press was repeated
    for (WORD i=0; i<ir.Event.KeyEvent.wRepeatCount; ++i) {

        //	Switch depending on the key
        //	pressed
        switch (ir.Event.KeyEvent.wVirtualKeyCode) {

        case VK_RETURN: {

            //	Enter was pressed

            //	Get line from the screen
            String line(buffer.Return());
            //	Dispatch callback (if applicable)
            if (callback) callback(std::move(line));

        }
        break;

        case VK_HOME:

            //	Home was pressed

            //	Fire appropriate event
            //	depending on whether CTRL
            //	is pressed or not
            if (ctrl_pressed(ir)) buffer.CtrlHome();
            else buffer.Home();

            break;

        case VK_END:

            //	End was pressed

            //	Fire appropriate event
            //	depending on whether
            //	CTRL is pressed or not
            if (ctrl_pressed(ir)) buffer.CtrlEnd();
            else buffer.End();

            break;

        case VK_RIGHT:

            //	Right was pressed

            buffer.Right();

            break;

        case VK_LEFT:

            //	Left was pressed

            buffer.Left();

            break;

        case VK_DELETE:

            //	Delete was pressed

            buffer.Delete();

            break;

        case VK_BACK:

            //	Backspace was pressed

            buffer.Backspace();

            break;

        case VK_PRIOR:

            //	Page Up was pressed

            buffer.PageUp();

            break;

        case VK_NEXT:

            //	Page Down was pressed

            buffer.PageDown();

            break;

        default:

            if (ir.Event.KeyEvent.uChar.UnicodeChar!=0) buffer.Add(
                    static_cast<CodePoint>(
                        ir.Event.KeyEvent.uChar.UnicodeChar
                    )
                );

            break;

        }

    }

}