IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

deplacer la souris


Sujet :

C++Builder

  1. #1
    Membre à l'essai
    Inscrit en
    Août 2004
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 28
    Points : 20
    Points
    20
    Par défaut deplacer la souris
    Bonjour,

    j aimerais savoir si borland offre la possibilite de deplacer la souris a partir du code.
    Typiquement, je cree un bouton et lorsque je click dessus, la souris effectue un deplacement predefini.

    Merci d avance!!

  2. #2
    Membre expérimenté Avatar de 10_GOTO_10
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    887
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 887
    Points : 1 531
    Points
    1 531
    Par défaut
    Tout à fait.

    Exemple:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    //---------------------------------------------------------------------------
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "JeanPaul2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
      : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
      Timer = new TTimer(this);
      Timer->Interval = 50;
      Timer->OnTimer = Timer1Timer;
    }
    void __fastcall TForm1::Timer1Timer(TObject *Sender)
    {
      INPUT Input;
     
     
      Input.type = INPUT_MOUSE;
      Input.mi.dx = 10 * rand() / RAND_MAX - 5;
      Input.mi.dy = 10 * rand() / RAND_MAX - 5;
      Input.mi.mouseData = 0;
      Input.mi.dwFlags = MOUSEEVENTF_MOVE;
      Input.mi.time = 0;
      Input.mi.dwExtraInfo = GetMessageExtraInfo();
      SendInput(1, &Input, sizeof(Input));
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormDestroy(TObject *Sender)
    {
      delete Timer;
    }
    //---------------------------------------------------------------------------

  3. #3
    Membre à l'essai
    Inscrit en
    Août 2004
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 28
    Points : 20
    Points
    20
    Par défaut Merci!! mais si 2,3 explication sont possibles
    Voila, merci beaucoup ca marche bien mais je ne comprend pas bien la signification de ces quelques lignes...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
      Input.mi.mouseData = 0; 
      Input.mi.dwFlags = MOUSEEVENTF_MOVE; 
      Input.mi.time = 0; 
      Input.mi.dwExtraInfo = GetMessageExtraInfo(); 
      SendInput(1, &Input, sizeof(Input));
    Balises [Code] rajoutées par Ricky81
    Merci d'y penser à l'avenir

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 10
    Points : 10
    Points
    10
    Par défaut
    Sont aussi à ta disposition les fonctions GetCursorPos(POINT) et surtout SetCursorPos(POINT).

  5. #5
    Membre expérimenté Avatar de 10_GOTO_10
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    887
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 887
    Points : 1 531
    Points
    1 531
    Par défaut
    Citation Envoyé par Dans l'aide Windows, y'
    INPUT
    The INPUT structure is used by SendInput to synthesize keystrokes, mouse motions, and button clicks.

    typedef struct tagINPUT {
    DWORD type;
    union
    {
    MOUSEINPUT mi;
    KEYBDINPUT ki;
    HARDWAREINPUT hi;
    };
    } INPUT, *PINPUT, FAR* LPINPUT;

    Members
    type
    Specifies the type of the input event. It can be one of the following values. Value Meaning
    INPUT_MOUSE The event is a mouse event. Use the mi structure of the union.
    INPUT_KEYBOARD The event is a keyboard event. Use the ki structure of the union.
    INPUT_HARDWARE Windows 95: The event is from input hardware other than a keyboard or mouse. Use the hi structure of the union.


    mi
    Specifies a mouse event.
    typedef struct tagMOUSEINPUT {
    LONG dx;
    LONG dy;
    DWORD mouseData;
    DWORD dwFlags;
    DWORD time;
    DWORD dwExtraInfo;
    } MOUSEINPUT, *PMOUSEINPUT, FAR* LPMOUSEINPUT;

    dx, dy
    Specifies the mouse's absolute position or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE in dwFlags. Absolute data is given as the mouse's actual x- and y-coordinates; relative data is given as the number of pixels moved.
    mouseData
    If dwFlags contains MOUSEEVENTF_WHEEL, then mouseData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
    If dwFlags does not contain MOUSEEVENTF_WHEEL, then mouseData should be zero.

    dwFlags
    A set of bit flags that specify various aspects of mouse motion and button clicks. The bits in this member can be any reasonable combination of the following values. Value Meaning
    MOUSEEVENTF_ABSOLUTE Specifies that the dx and dy members contain normalized absolute coordinates. If the flag is not set, the dx and dy members contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or other pointing device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.
    MOUSEEVENTF_MOVE Specifies that movement occurred.
    MOUSEEVENTF_LEFTDOWN Specifies that the left button was pressed.
    MOUSEEVENTF_LEFTUP Specifies that the left button was released.
    MOUSEEVENTF_RIGHTDOWN Specifies that the right button was pressed.
    MOUSEEVENTF_RIGHTUP Specifies that the right button was released.
    MOUSEEVENTF_MIDDLEDOWN Specifies that the middle button was pressed.
    MOUSEEVENTF_MIDDLEUP Specifies that the middle button was released.
    MOUSEEVENTF_WHEEL Windows NT: Specifies that the wheel was moved, if the mouse has a wheel. The amount of movement is specified in mouseData.


    The bit flags that specify mouse button status are set to indicate changes in status, not ongoing conditions. For example, if the left mouse button is pressed and held down, MOUSEEVENTF_LEFTDOWN is set when the left button is first pressed, but not for subsequent motions. Similarly, MOUSEEVENTF_LEFTUP is set only when the button is first released.

    time
    Time stamp for the event.
    dwExtraInfo
    Specifies an additional 32-bit value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.
    ki
    Specifies a keyboard event.
    typedef struct tagKEYBDINPUT {
    WORD wVk;
    WORD wScan;
    DWORD dwFlags;
    DWORD time;
    DWORD dwExtraInfo;
    } KEYBDINPUT, *PKEYBDINPUT, FAR* LPKEYBDINPUT;

    wVk
    Specifies a virtual-key code. The code must be a value in the range 1 to 254.
    wScan
    Specifies a hardware scan code for the key.
    dwFlags
    A set of bit flags that specify various aspects of a keystroke. The bits in this member can be any combination of the following predefined constant values. Value Meaning
    KEYEVENTF_EXTENDEDKEY If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224).
    KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is being pressed.


    time
    Time stamp for the event.
    dwExtraInfo
    Specifies an additional 32-bit value associated with the keystroke. An application calls GetMessageExtraInfo to obtain this extra information.
    hi
    Windows 95: Specifies an event from input hardware other than a keyboard or mouse.
    typedef struct tagHARDWAREINPUT {
    DWORD uMsg;
    WORD wParamL;
    WORD wParamH;
    DWORD dwExtraInfo;
    } HARDWAREINPUT, *PHARDWAREINPUT, FAR* LPHARDWAREINPUT;

    uMsg
    The message generated by the input hardware.
    wParamL
    Parameter for uMsg.
    wParamH
    Parameter for uMsg.
    dwExtraInfo
    Specifies an additional 32-bit value associated with the event. An application calls GetMessageExtraInfo to obtain this extra information.
    Remarks
    If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy specify information about that motion. The information is given as absolute or relative integer values.

    If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface; coordinate (65535,65535) maps onto the lower-right corner.

    If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify motions relative to the previous mouse event (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up).

    Relative mouse motion is subject to the effects of the mouse speed and the two mouse threshold values. A user sets these three values with the Pointer Speed slider of the Control Panel's Mouse Properties sheet. An application obtains and sets these values with theSystemParametersInfo function.

    The operating system applies two tests to the specified relative mouse motion. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse speed is not zero, the operating system doubles the distance. If the specified distance along either the x or y axis is greater than the second mouse threshold value, and the mouse speed is equal to two, the operating system doubles the distance that resulted from applying the first threshold test. It is thus possible for the operating system to multiply specified relative mouse motion along the x or y axis by up to four times.

    QuickInfo
    Windows NT: Requires version 4.0 SP3 or later.
    Windows: Requires Windows 98 or later.
    Windows CE: Unsupported.
    Header: Declared in winuser.h.

    See Also
    Keyboard Input Overview, Keyboard Input Structures, GetMessageExtraInfo, SendInput,SystemParametersInfo


  6. #6
    Membre à l'essai
    Inscrit en
    Août 2004
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 28
    Points : 20
    Points
    20
    Par défaut derniere petite chose...
    je n arrive pas a simuler un click,ceci garde la souris clicke:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
    alors j ai essaye cela mais cela ne fonctionne pas:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;   
    Sleep(500);
    Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;

  7. #7
    Membre expérimenté Avatar de 10_GOTO_10
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    887
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 887
    Points : 1 531
    Points
    1 531
    Par défaut
    N'oublie pas de faire un SendInput à chaque fois:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
    SendInput(1, &Input, sizeof(Input));  
    Sleep(500); 
    Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
    SendInput(1, &Input, sizeof(Input));

  8. #8
    Membre à l'essai
    Inscrit en
    Août 2004
    Messages
    28
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 28
    Points : 20
    Points
    20
    Par défaut
    Merci beaucoup!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Problemes resolus!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Deplacer la souris
    Par maitrebido dans le forum Langage
    Réponses: 2
    Dernier message: 22/08/2013, 07h43
  2. Réponses: 1
    Dernier message: 28/09/2010, 11h26
  3. [XL-2007] Macro pour deplacer la souris
    Par bluesun91 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 13/06/2010, 23h21
  4. Deplacer la souris ou en veut
    Par maxime528 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 12/08/2009, 15h23
  5. deplacer la souris sur un element
    Par lacsap49 dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 17/03/2006, 22h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo