Faire croire à un programme qu'on appui sur le clavier

Programmation d'applications complexes
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Faire croire à un programme qu'on appui sur le clavier

Message par Le Soldat Inconnu »

Salut,

Comment faire pour faire croire à un programe que l'on appui sur une touches ?

Merci
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Fred
Site Admin
Messages : 2808
Inscription : mer. 21/janv./2004 11:03

Message par Fred »

Regarde du coté de keybd_event_() ca devrait faire ce que tu veux. Sinon, tu peux envoyer une sequence WM_KEYDOWN/WM_KEYUP à une application (PostMessage()) ce qui devrait aussi faire l'affaire.
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

Merci, je fais des essais ce soir et soit je donnne une solution commentée, soit je je rale car j'ai pas trouvé :mrgreen:
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Patrick88
Messages : 1564
Inscription : mer. 21/janv./2004 18:24

Message par Patrick88 »

de mémoire, ça déja été posé cette question...

tu as regardé sur les anciens forums, celui de chris et de cede ?

pat
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

bon, la solution :

Code : Tout sélectionner

Procedure Clavier(WindowID, Touche)
  SetForeGroundWindow_(WindowID)
  UpdateWindow_(WindowID)
  If OpenLibrary(0, "user32.dll")
    CallFunction(0, "keybd_event", Touche, 0, 0, 0)
    CallFunction(0, "keybd_event", Touche, 0, #KEYEVENTF_KEYUP, 0)
    CloseLibrary(0)
  EndIf
EndProcedure
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

mince et zut zut et zut.

ça marche pas avec les boutons control et alt

Code : Tout sélectionner

Procedure Clavier(WindowID, Touche)
  SetForeGroundWindow_(WindowID)
  UpdateWindow_(WindowID)
  
  If OpenLibrary(0, "user32.dll")
    
    If Touche & #PB_Shortcut_Control
      CallFunction(0, "keybd_event", #PB_Shortcut_Control, 0, #KEYEVENTF_EXTENDEDKEY, 0)
      Touche = Touche ! #PB_Shortcut_Control
      CallFunction(0, "keybd_event", Touche, 0, 0, 0)
      CallFunction(0, "keybd_event", Touche, 0, #KEYEVENTF_KEYUP, 0)
      CallFunction(0, "keybd_event", #PB_Shortcut_Control, 0, #KEYEVENTF_EXTENDEDKEY | #KEYEVENTF_KEYUP, 0)
    ElseIf Touche & #PB_Shortcut_Alt
      CallFunction(0, "keybd_event", #PB_Shortcut_Alt, 0, #KEYEVENTF_EXTENDEDKEY, 0)
      Touche = Touche ! #PB_Shortcut_Alt
      CallFunction(0, "keybd_event", Touche, 0, 0, 0)
      CallFunction(0, "keybd_event", Touche, 0, #KEYEVENTF_KEYUP, 0)
      CallFunction(0, "keybd_event", #PB_Shortcut_Alt, 0, #KEYEVENTF_EXTENDEDKEY | #KEYEVENTF_KEYUP, 0)
    Else
      CallFunction(0, "keybd_event", Touche, 0, 0, 0)
      CallFunction(0, "keybd_event", Touche, 0, #KEYEVENTF_KEYUP, 0)
    EndIf
    
    CloseLibrary(0)
  EndIf
EndProcedure

; Procedure Clavier(WindowID, Touche)
;   SetForeGroundWindow_(WindowID)
;   UpdateWindow_(WindowID)
;   If OpenLibrary(0, "user32.dll")
;     CallFunction(0, "keybd_event", Touche, 0, , 0)
;     CallFunction(0, "keybd_event", Touche, 0, #KEYEVENTF_KEYUP, 0)
;     CloseLibrary(0)
;   EndIf
; EndProcedure

Delay(1000)

WindowE = GetForegroundWindow_()

OpenWindow(0, 200, 200, 500, 500, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget, "Options")

; PostMessage_(WindowE, #WM_KEYDOWN, #PB_Shortcut_N, 0)

clavier(WindowE, #PB_Shortcut_Control | #PB_Shortcut_N)


Repeat
  Event = WaitWindowEvent()
  
Until Event = #WM_CLOSE

normalement, j'envoie la touche Ctrl + N donc j'ouvre un nouveau fichier mais ça écrit simplement N dans le code.
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

bon, j'ai trouvé la fonction
PostKeybdMessage
This function posts a keyboard message to the specified window.

BOOL PostKeybdMessage(
HWND hwnd,
UINT VKey,
KEY_STATE_FLAGS KeyStateFlags,
UINT cCharacters,
UINT *pShiftStateBuffer,
UINT *pCharacterBuffer );
Parameters

hwnd
[in] Handle to the window that receives the message. It must identify a window owned by the calling thread. If hwnd is NULL, then the keyboard message is sent to the active window or window with the focus of the calling thread. If hwnd is –1, then the keyboard message is sent to the active window or window with the focus of the system foreground thread.
VKey
[in] Virtual key code. This parameter can be set to 0.
KeyStateFlags
[in] State of the key. The key states are described in the following table. Flag Description
KeyStateToggledFlag Key is toggled.
KeyStatePrevDownFlag Key was previously down.
KeyStateDownFlag Key is currently down.
KeyShiftAnyCtrlFlag Left or right CTRL key is down.
KeyShiftAnyShiftFlag Left or right SHIFT key is down.
KeyShiftAnyAltFlag Left or right ALT key is down.
KeyShiftCapitalFlag VK_CAPITAL is toggled.
KeyShiftLeftCtrlFlag Left CTRL key is down.
KeyShiftLeftShiftFlag Left SHIFT key is down.
KeyShiftLeftAltFlag Left ALT key is down.
KeyShiftLeftWinFlag Left Windows logo key is down.
KeyShiftRightCtrlFlag Right CTRL key is down.
KeyShiftRightShiftFlag Right SHIFT key is down.
KeyShiftRightAltFlag Right ALT key is down.
KeyShiftRightWinFlag Right Windows logo key is down
KeyShiftDeadFlag Corresponding character is dead character.
KeyShiftNoCharacterFlag No characters in pCharacterBuffer to translate.

cCharacters
[in] Number of characters in the pCharacterBuffer array.
pCharacterBuffer
[in] Pointer to a buffer that contains the characters to send. This parameter cannot be NULL.
pShiftStateBuffer
[in] Pointer to a buffer that contains a corresponding shift state entry for each character in the pCharacterBuffer array. The shift state for each character must be the same as the KeyStateFlags parameter. This parameter cannot be NULL.
http://msdn.microsoft.com/library/defau ... eydown.asp

le problème est le suivant, j'ai pas la valuer des constantes et j'ai pas la librairie qui contient cette fonction. ouin, j'arrive à rien :cry:

j'ai fait ce code et je peux pas le tester :

Code : Tout sélectionner

Procedure Clavier(WindowID, Touche)
  If OpenLibrary(0, "user32.dll")
    KeyState = #KeyStateDownFlag
    If Touche & #PB_Shortcut_Control
      Touche = Touche & #PB_Shortcut_Control
      KeyState = KeyState | #KeyShiftAnyCtrlFlag
    ElseIf Touche & #PB_Shortcut_Alt
      Touche = Touche & #PB_Shortcut_Alt
      KeyState = KeyState | #KeyShiftAnyAltFlag
    EndIf
    CallFunction("PostKeybdMessage", WindowID, 0, KeyState, 1, @Touche, @Touche)
    closelibrairy(0)
  EndIf
EndProcedure

Delay(1000)

WindowE = GetForegroundWindow_()


; PostMessage_(WindowE, #WM_KEYDOWN, #PB_Shortcut_N, 0)

clavier(WindowE, #PB_Shortcut_Control | #PB_Shortcut_N)
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Message par Anonyme2 »

Cherches pas plus, c'est uniquement pour WIndows CE 1, 2 ou supérieur.

C'est d'ailleurs indiqué en haut de la page de ton lien et j'ai rien trouvé sur la Doc SDK.
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

heu, c'est quoi, win CE ????

bon, ben on revient plus haut avec mon prob pour les touches control et alt.
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

J'ai finit par trouvé, et tout seul comme un grand :wink:

Code : Tout sélectionner

Procedure KeyBoardEvent(WindowID, Touche, ToucheSpecial)
  ; WindowID : fenêtre qui va recevoir la touche
  ; Touche : Touche appuyée, voir constantes PB dans l'aide de AddKeyboardShortcut()
  ; ToucheSpecial :
  ; = 1 si touche Control appuyée
  ; = 2 si touche Alt appuyée
  ; = 0 sinon
  
  SetForeGroundWindow_(WindowID)
  
  If OpenLibrary(0, "user32.dll")
    
    Select ToucheSpecial
      Case 1
        CallFunction(0, "keybd_event", #VK_CONTROL, 0, 0, 0)
      Case 2
        CallFunction(0, "keybd_event", #VK_MENU, 0, 0, 0)
    EndSelect
    
    CallFunction(0, "keybd_event", Touche, 0, 0, 0)
    Delay(10)
    CallFunction(0, "keybd_event", Touche, 0, #KEYEVENTF_KEYUP, 0)
    
    Select ToucheSpecial
      Case 1
        CallFunction(0, "keybd_event", #VK_CONTROL, 0, #KEYEVENTF_KEYUP, 0)
      Case 2
        CallFunction(0, "keybd_event", #VK_MENU, 0, #KEYEVENTF_KEYUP, 0)
    EndSelect
    
    CloseLibrary(0)
  EndIf
EndProcedure



; Debut du test

Delay(1000)

WindowE = GetForegroundWindow_()

KeyBoardEvent(WindowE, #PB_Shortcut_N, 1)
KeyBoardEvent(WindowE, #PB_Shortcut_Z, 0)
KeyBoardEvent(WindowE, #PB_Shortcut_U, 0)
KeyBoardEvent(WindowE, #PB_Shortcut_T, 0)
KeyBoardEvent(WindowE, #PB_Shortcut_A, 2)
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
david
Messages : 208
Inscription : jeu. 03/févr./2005 21:10

Message par david »

j'ai bien regardé cet exemple mais je me demande comment
on peut avoir la liste des éléments contenus dans une DLL?

a savoir que moi je veux simuler un appuie sur ENTREE
et que j'ai essayé à taton des paramètres...et qu'il me dit que ça
n'existe pas

y a pas un lexique de la DLL?
sinon quel mot magique je dois lui demander? ...ENTER, ...RETURN...??
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

a tout hasard essaye

Code : Tout sélectionner

KeyBoardEvent(WindowE, #VK_RETURN, 0)
:)
Répondre