Page 1 sur 1

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

Publié : mar. 16/mars/2004 9:39
par Le Soldat Inconnu
Salut,

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

Merci

Publié : mar. 16/mars/2004 11:09
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.

Publié : mar. 16/mars/2004 11:50
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:

Publié : mar. 16/mars/2004 12:39
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

Publié : mer. 17/mars/2004 12:19
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

Publié : sam. 20/mars/2004 8:30
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.

Publié : sam. 20/mars/2004 18:47
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)

Publié : sam. 20/mars/2004 19:45
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.

Publié : sam. 20/mars/2004 19:55
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.

Publié : dim. 21/mars/2004 19:45
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)

Publié : lun. 15/oct./2007 8:50
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...??

Publié : lun. 15/oct./2007 9:42
par Backup
a tout hasard essaye

Code : Tout sélectionner

KeyBoardEvent(WindowE, #VK_RETURN, 0)
:)