Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    142

    [C++] Spostare cursore con la tastiera

    Salve a tutti io ho questo codice fatto da me solo che non riesco a far spostare il cursore come mai?:
    codice:
    #include <stdlib.h>
    #include <conio.h>
    #include <iostream>
    #include "crt.h"
    using namespace std;
    
    
    
    int main()										
    {													
      char tasto1=' ',tasto2=' ';
      int cx=1,cy=1;
      	
      	TextBackground(WHITE);
      	clrscr();
      	TextColor (BLUE);
    	do										
    	{					
         					
    	    tasto1 = getch();
    	    if ((tasto1 >= 32)&&(tasto1<=127)){
    	       cout<<tasto1;
    	       cx++;
    	    }  
            if (tasto1 == 13){        
    	       cy++;
    	       cx = 1;
    	       gotoxy(cx,cy);
    	    }    
    	    if ((tasto1 == 0)|| (tasto1 == -32)){
    	       tasto2 = getch();
    	       //cout<< int(tasto2)<<"   Tasto cursore o tasto funzione "<<endl;
    	       switch (tasto2){
    	         case 72 :   if (cy > 1) cy = cy--; gotoxy(cx,cy);break;  
    	         case 75 :   if (cx > 1) cx = cx--; gotoxy(cx,cy);break;
    	         case 77 :   if (cx < 80) cx = cx++; gotoxy(cx,cy);break;
    	         case 80 :   if (cy < 25) cy = cy++; gotoxy(cx,cy);break;  
    	       }       
    	      
    	    }      
         
         
        }while(tasto1!=27);
         
         system("pause");
         return 0;
    }
    grazie a tutti coloro che mi aiuteranno

  2. #2
    Utente bannato
    Registrato dal
    Feb 2004
    Messaggi
    2,803
    codice:
    #include <windows.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include <iostream>
    #include <winable.h>
    
    int x=100;
    int y=100;
    int i=0;
    int a=0;
    
    int left_click()
    {
        // left mouse button down
        INPUT    Input={0};
        Input.type      = INPUT_MOUSE;
        Input.mi.dwFlags  = MOUSEEVENTF_LEFTDOWN;
        
        ::SendInput(1,&Input,sizeof(INPUT));
       
        // left mouse button up
        ::ZeroMemory(&Input,sizeof(INPUT));
        Input.type      = INPUT_MOUSE;
        Input.mi.dwFlags  = MOUSEEVENTF_LEFTUP;
    
        ::SendInput(1,&Input,sizeof(INPUT));
        
    }
    int right_click()
    {
        // right mouse button down
        INPUT    Input={0};
        Input.type      = INPUT_MOUSE;
        Input.mi.dwFlags  = MOUSEEVENTF_RIGHTDOWN;
        ::SendInput(1,&Input,sizeof(INPUT));
       
        // right mouse button up
        ::ZeroMemory(&Input,sizeof(INPUT));
        Input.type      = INPUT_MOUSE;
        Input.mi.dwFlags  = MOUSEEVENTF_RIGHTUP;
        ::SendInput(1,&Input,sizeof(INPUT));
    }
    
    
    
    void controlla_tastiera(){
    
         if (GetAsyncKeyState(37)) {
                                     x-=10;
                                     SetCursorPos(x,y);
                          
                                     }
         if (GetAsyncKeyState(38)) {
                                     y-=20;
                                     SetCursorPos(x,y);
                                     }
         if (GetAsyncKeyState(39)) {
                                     x+=10;
                                     SetCursorPos(x,y);
                                     }
         if (GetAsyncKeyState(40)) {
                                     y+=20;
                                     SetCursorPos(x,y);
                                     }
         
         //left click tasto PAUSE
          if(GetAsyncKeyState(45)==-32767){
          
          left_click();
          
         }
    }
    int main() {
    
    
       while(1){
      
                 controlla_tastiera();
                 Sleep(30);}
    
    }
    ti posto la mia soluzione
    ovviamente cambiando i keycode puoi cambiare i tasti di controllo, se qlc non è chiaro dimmi
    (il tasto dx non ha il suo tasto, ma credo che il codice sia più che banale da modificare per usarlo )

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    142
    grazie mille

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.