Ascii

This is a discussion on Ascii within the C++ Programming forums, part of the General Programming Boards category; Try using Borland 's command-line compiler (in the second table on that linked page named "Compiler"). It is free and ...

  1. #16
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Try using Borland's command-line compiler (in the second table on that linked page named "Compiler"). It is free and works very well, but you may not be too keen on it because the free version includes no IDE. Iow, you have to compile by typing a command line. It's actually the only compiler I use except when the situation requires otherwise.

    Good luck to you.

  2. #17
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >LuckY, what compiler do you use? (I use dev-c++) the code you gave me doesnt run...
    Change cprintf to printf. It compiles fine under Dev-C++ after making that change.

  3. #18
    Registered User Bag a Bones's Avatar
    Join Date
    Dec 2005
    Posts
    15
    Ok, now LuckY's program works, but it returns the same values as the number keys (the ones above the letters). I need to know how to tell when and what numpad keys are pressed. Im kind of in a rush, this is due on Friday...

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    That's only possible using GetAsyncKeyState, a function from windows.h. Or by having a full message loop, but then you can't use the Windows console anymore.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #20
    Registered User Bag a Bones's Avatar
    Join Date
    Dec 2005
    Posts
    15
    Im already using GetAsyncKeyState. How do I know when the numpad keys?

    At this point im going to put up my code, so everyone can see what im doing. You don't have to take it and edit it and spit it back out. Infact, please don't. I would rather learn how to do it than have someone do it for me.

    Code:
    #include <iostream>
    #include <stdio.h>
    #include <conio.h>
    #include <windows.h>
    
    #define SHIFTED 0x8000
    
    //define variables
    int LEFT; int RIGHT; int UP; int DOWN;
    int LSHIFT; int RSHIFT;
    int ENTER;
    int LALT; int RALT;
    int PRESSED;
    int scale;
    
    int main ( void ){
       //set arrow-key keycodes
       LEFT=37; RIGHT=39; UP=38; DOWN=40;
       //set shift keycodes
       LSHIFT=160; RSHIFT=161;
       //set enter keycode
       ENTER=13;
       //set alt keycodes
       LALT=164; RALT=165;
       //set key-pressed value
       PRESSED=-32767;
       //set default movement scale
       scale=2;
          
       //define cursor point
       POINT XY;
       
       //print instructions
       cout<<"Use the arrow keys to move the cursor, hold SHIFT to move the cursor faster."<<endl;
       cout<<"Press ENTER to left-click, and ALT to right-click."<<endl;
       
       //main loop
       while(1==1)
       
       {
           
           //if enter pressed then left-click
           if(GetAsyncKeyState(ENTER)==PRESSED){
               mouse_event(MOUSEEVENTF_LEFTDOWN, XY.x, XY.y, 0, 0);
               Sleep(100);
               mouse_event(MOUSEEVENTF_LEFTUP, XY.x, XY.y, 0, 0);
           }  
           
           //if alt pressed then right-click
           if(GetAsyncKeyState(LALT)==PRESSED||GetAsyncKeyState(RALT)==PRESSED){
               mouse_event(MOUSEEVENTF_RIGHTDOWN, XY.x, XY.y, 0, 0);
               Sleep(100);
               mouse_event(MOUSEEVENTF_RIGHTUP, XY.x, XY.y, 0, 0);
           }    
           
           //move mouse with arrow keys. set scale to 10 if shift is pressed, else 2
           if(GetAsyncKeyState(LEFT)==PRESSED){
               if(GetKeyState(LSHIFT) & SHIFTED||GetKeyState(RSHIFT) & SHIFTED){
                   scale=10;
               }else{
                   scale=2;
               }
               GetCursorPos( &XY );
               SetCursorPos( XY.x - scale, XY.y);
           }
           if(GetAsyncKeyState(RIGHT)==PRESSED){
               if(GetKeyState(LSHIFT) & SHIFTED||GetKeyState(RSHIFT) & SHIFTED){
                   scale=10;
               }else{
                   scale=2;
               }
               GetCursorPos( &XY );
               SetCursorPos( XY.x + scale, XY.y);
           }
           if(GetAsyncKeyState(UP)==PRESSED){
               if(GetKeyState(LSHIFT) & SHIFTED||GetKeyState(RSHIFT) & SHIFTED){
                   scale=10;
               }else{
                   scale=2;
               }
               GetCursorPos( &XY );
               SetCursorPos( XY.x, XY.y - scale );
           }
           if(GetAsyncKeyState(DOWN)==PRESSED){
               if(GetKeyState(LSHIFT) & SHIFTED||GetKeyState(RSHIFT) & SHIFTED){
                   scale=10;
               }else{
                   scale=2;
               }
               GetCursorPos( &XY );
               SetCursorPos( XY.x, XY.y + scale );
           }
       }
       return 0;    
    }

  6. #21
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    http://msdn.microsoft.com/library/de...alKeyCodes.asp

    Lists all the valid parameters to GetAsyncKeyState. There are VK_NUMPADn constants there, too.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASCII character with ASCII value 0 and 32
    By hitesh_best in forum C Programming
    Replies: 4
    Last Post: 07-24-2007, 09:45 AM
  2. Replies: 11
    Last Post: 03-24-2006, 10:26 AM
  3. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 01:43 PM
  4. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM
  5. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 07:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21