Thread: Cursor, UNICODE and VK's

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question Cursor, UNICODE and VK's

    Hi!

    First problem is that I can't get rid of the cursor in my win32 console application.

    I tried this and it is not working:
    Code:
    CONSOLE_CURSOR_INFO cci;
    HANDLE hStdout;
    
    hStdout = GetStdHandle (STD_OUTPUT_HANDLE);
    cci.bVisible = FALSE;
    SetConsoleCursorInfo (hStdout, &cci);
    What is wrong with my code?

    My second problem is with the output (on screen) of my program. In my program I'm using "šèž" characters.

    If I have a windowed program then the characters "šèž" are displayed properly but if I have a fullscreen program then these characters become "£ß¤". How to get rid of this problem? Is the UNICODE the solution, if it is how to use it?

    And the third problem is with virtual keys.

    For left and right arrow I use VK_LEFT and VK_RIGHT. I tried to use a key 'f' or any other key like this: case 'f': ..., but it is not working. Why? And I want to have a shortcut ALT+F. How to do this with virtual keys?

    Here's the code:
    Code:
    INPUT_RECORD ir;
    DWORD dwRead = 0;
    BOOL Loop;
    
    while (Loop)
    {
      if ( ReadConsoleInput(hInput, &ir, 1, &dwRead) 
        && (ir.EventType == KEY_EVENT) 
        && (ir.Event.KeyEvent.bKeyDown) )
      {
        switch (ir.Event.KeyEvent.wVirtualKeyCode)
        {
          case 'f': // this is not working, why?
            printf ("Hello!");
            break;
          case VK_LEFT: // this is working
            printf ("Hi!");
            break;
          case ALT+F: // this not working too, why?
            printf ("Not working!");
            break;
        }
      }
    }
    I'm using VC++ 6.0 on Win98. Any help would be appreciated.
    Last edited by GaPe; 04-06-2002 at 02:21 PM.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    as for the cursor problem try adding this line
    Code:
    cci.dwSize = 1;
    before you call SetConsoleCursorInfo().
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    1. The ALT-f thing....

    I think when pressing alt-f....the following will occur;
    Code:
    ir.Event.KeyEvent.uChar == 'f'
    and
    Code:
    ir.Event.KeyEvent.dwControlKeyState == LEFT_ALT_PRESSED
    2. Kill the cursor...

    I did this on a console snake game I did one......I think the code that did it for me was

    Code:
    SetConsoleMode(hIn,ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT |
     ENABLE_ECHO_INPUT );
    ...but I am not sure....the hIn is the Input handle...not output BTW

    3. Weird Unicode thing...

    Wow that's weird.....Have you tried to use the Unicode safer functions and used the _T() macros on all literals?.......If you want more you should lookup a tutorial on Unicode.......I am not sure if this is the problem though...I am guessing a bit

  4. #4
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    C_Coder Your code is not working. Instead at the bottom of the screen, the cursor shows at the top of the screen.

    Fordy

    The Alt-f code...I can't get it working. And the kill cursor code is not working. About the unicode, I don't know which functions to use.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  5. #5
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    is this what you tried?
    Code:
    void kill_cursor( void )
    {
    	CONSOLE_CURSOR_INFO cci;
    
    	cci.dwSize = 1;
    	cci.bVisible = FALSE;
    	SetConsoleCursorInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &cci );
    }
    it kills the cursor for me. I don't see how it could change you cursor position either.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  6. #6
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Yes and it's not working. This is totally wierd.

    EDIT:

    I tried in full screen mode and the cursor disappeared. But in the window mode the cursor change it's position.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    The Alt-f code...I can't get it working.
    This should work

    Code:
    if ( ReadConsoleInput(hInput, &ir, 1, &dwRead)
        && (ir.EventType == KEY_EVENT)
        && (ir.Event.KeyEvent.bKeyDown) )
    		{	
    		switch (ir.Event.KeyEvent.wVirtualKeyCode)
    			{
    		
    		case VK_LEFT: // this is working
    			printf ("Hi!");
    			break;
    
    		default:
    			if(ir.Event.KeyEvent.dwControlKeyState == 34
    				 && ir.Event.KeyEvent.uChar.AsciiChar == 'f')
    			printf ("alt f");
    			break;
          
        }
    	
      }

    And the kill cursor code is not working.
    My code works for me....bu only when the console is in full screen mode.......


    About the unicode, I don't know which functions to use.
    I'm not going to describe Unicode or its functions & Macros here....its too much work....try reading a few tutorials on the web

  8. #8
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    I tried in full screen mode and the cursor disappeared. But in the window mode the cursor change it's position.
    Mmm strange indeed, the code works in window and full screen for me.
    I guess some other piece of code must be acting with it to cause this problem???
    I'm using msvc 6 as well.
    Last edited by C_Coder; 04-06-2002 at 03:18 PM.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  9. #9
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    The Alt+f thing is now working , but I wonder what is the ASCII code for the left ctrl? I know that for the left alt is 34, right alt is 33 and the right ctrl is 36.

    That cursor is driving me crazy. I just can't get it working .
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    MSDN says its LEFT_CTRL_PRESSED......which is 8....but on debug, it shows to be 40.....try that.....oh and its NOT ASCII btw

  11. #11
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Yes 40 is the right one.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed