Page 1 sur 1

exécution diffée et simule un appuie de touche

Publié : dim. 14/oct./2007 10:07
par david
c'est un peu décousus mais dansle morceau de programme que j'essaie de faire je veux qu'il lance une application a uneheure déterminée

j'ai essayé avec:

Code : Tout sélectionner

Time$ = FormatDate("%hh:%ii:%ss", Date())

If Time$="14:30:00" : MessageRequester("TESTEUR", "Heure ok: "+Time$, 0)
mais je ne parviens pas a boucler

al'heure dite j'ouvre mon application:

Code : Tout sélectionner

RunProgram("excel.exe","C:\_work\Fred\MAJ_Auto\Mafeuille.xls","")
mais comme Excel me pose une question je veux faire un appuie automatique (comme si jetapais sur ENTREE). mais j'ai l'impression que

Code : Tout sélectionner

KeyboardPushed
teste l'appuie d'une touche mais ne simule pas un appuie?!

Après je marque une pause

Code : Tout sélectionner

Delay(1000)
Et je veux forcer excel a se refermer comme je l'ai ouvert(mais j'arrive pas non plus)
là comme il me demande si je veux enregistrer j'aurais fimuler également un appuie sur ENTREE...

Je suis désollé d'embêter le monde mais je débute et c'estpas facile
meme si l'aide de purebasic est quand meme tres bien faite et que je trouve souvent des aides dans les articles

si quelqu'un peu m'aider ou me donner une piste...
d'avance merci

Publié : dim. 14/oct./2007 10:21
par Kwai chang caine
Bonjour DAVID

Deja sache que tu ne nous embete pas, au contraire ça fait un membre de la famille de plus avec qui l'on peux converser :D
Et aussi aider, bien sur, ça sert à quoi sinon la famille :wink:
Et puis celui qui ne veux pas répondre est libre de le faire, comme aurait dit mon ami FLYPE

Bref, comme tu le sais, je suis loin d'etre un crack, mais j'ai quelques codes de simulation d'appuie de touches (qui ne sont pas de moi, of course) dans ma hotte.
Je te les donnes si ça peux t'aider en attendant les CRACKS qui doivent dormir car les programmeurs, c'est comme les chouettes, ça ne sort que la nuit :lol:

1er code

Code : Tout sélectionner

If OpenWindow(0,200,200,400,100,"Typing Test", #PB_Window_SystemMenu,0) 

 If CreateGadgetList(WindowID(0)) 

  TextGadget(0,0,0,400,20,"Click the button to simulate keystrokes!") 
  TextGadget(1,0,30,400,20,"Simulated and detected: ") 
  ButtonGadget(2,0,60,100,25,"Start typing") 

  Repeat 
 
   ev=WaitWindowEvent() 
 
   If ev=#PB_Event_Gadget And EventGadget()=2 
 
    SetGadgetText(1,"Simulated and detected: ") 
 
    For a=65 To 90 
     
     ; Next line simulates the keypresses. 
     keybd_event_(a,0,0,0) 
     keybd_event_(a,0,#KEYEVENTF_KEYUP,0) 
   
     If GetAsyncKeyState_(a)<>0 ; This line detects them (keylogger). 
      a$=GetGadgetText(1)+Chr(a) 
      SetGadgetText(1,a$) 
     EndIf 
    
    Next 
   
   EndIf 
  
  Until ev=#PB_Event_CloseWindow 
 
 EndIf 
EndIf 
2e code

Code : Tout sélectionner

; German forum:
; Author: Danilo
; Date: 07. April 2003


; Posted 07 April 2003 by Danilo on german forum

;SendKeys(handel,Window$,Keys$) 

;Handel ......... ist ein Handel zu einen Fenster bekommst du wenn du das Fenster erzeugst. 
;Window$ ........ Ist der Name des Fesnters, wenn du den Handel nicht kennst. In dem Fall gibt man dan Handel = 0 an. 
;Keys$ .......... Sind die Tasten die du schicken möchtest, wobei du Sondertasten in {} Einschliest (zb. {CONTROLDOWN}) 

; SendKeys procedure by PB -- do whatever you want with it. :) 
; Syntax: r=SendKeys(handle,window$,keys$) ; r = 0 for failure. 
; Specify either a handle or window$ title to type to, but not both! 
; You cannot type curly braces { } as part of the keystrokes, sorry! 
; 
Procedure SendKeys(handle,window$,keys$) 
If window$<>"" : handle=FindWindow_(0,window$) : EndIf ; Use window$ instead of handle. 
   If IsWindow_(handle)=0 ; Does the target window actually exist? 
      ProcedureReturn 0 ; Nope, so report 0 for failure to type. 
   Else 
   ; This block gives the target window the focus before typing. 
   thread1=GetWindowThreadProcessId_(GetForegroundWindow_(),0) 
   thread2=GetWindowThreadProcessId_(handle,0) 
   If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#True) : EndIf 
      SetForegroundWindow_(handle) ; Target window now has the focus for typing. 
      Delay(125) ; 1/8 second pause before typing, to prevent fast CPU problems. 
      ; Now the actual typing starts. 
      For r=1 To Len(keys$) 
          vk$=Mid(keys$,r,1) 
          If vk$="{" ; Special key found. 
             s=FindString(keys$,"}",r+1)-(r+1) ; Get length of special key. 
             s$=Mid(keys$,r+1,s) ; Get special key name. 
             Select s$ ; Get virtual key code of special key. 
                Case "ALTDOWN" : keybd_event_(#VK_MENU,0,0,0) ; Hold ALT down. 
                Case "ALTUP" : keybd_event_(#VK_MENU,0,#KEYEVENTF_KEYUP,0) ; Release ALT. 
                Case "BACKSPACE" : vk=#VK_BACK 
                Case "CONTROLDOWN" : keybd_event_(#VK_CONTROL,0,0,0) ; Hold CONTROL down. 
                Case "CONTROLUP" : keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0) ; Release CONTROL. 
                Case "DELETE" : vk=#VK_DELETE 
                Case "DOWN" : vk=#VK_DOWN 
                Case "END" : vk=#VK_END 
                Case "ENTER" : vk=#VK_RETURN 
                Case "F1" : vk=#VK_F1 
                Case "F2" : vk=#VK_F2 
                Case "F3" : vk=#VK_F3 
                Case "F4" : vk=#VK_F4 
                Case "F5" : vk=#VK_F5 
                Case "F6" : vk=#VK_F6 
                Case "F7" : vk=#VK_F7 
                Case "F8" : vk=#VK_F8 
                Case "F9" : vk=#VK_F9 
                Case "F10" : vk=#VK_F10 
                Case "F11" : vk=#VK_F11 
                Case "F12" : vk=#VK_F12 
                Case "ESCAPE" : vk=#VK_ESCAPE 
                Case "HOME" : vk=#VK_HOME 
                Case "INSERT" : vk=#VK_INSERT 
                Case "LEFT" : vk=#VK_LEFT 
                Case "PAGEDOWN" : vk=#VK_NEXT 
                Case "PAGEUP" : vk=#VK_PRIOR 
                Case "PRINTSCREEN" : vk=#VK_SNAPSHOT 
                Case "RETURN" : vk=#VK_RETURN 
                Case "RIGHT" : vk=#VK_RIGHT 
                Case "SHIFTDOWN" : shifted=1 : keybd_event_(#VK_SHIFT,0,0,0) ; Hold SHIFT down. 
                Case "SHIFTUP" : shifted=0 : keybd_event_(#VK_SHIFT,0,#KEYEVENTF_KEYUP,0) ; Release SHIFT. 
                Case "TAB" : vk=#VK_TAB 
                Case "UP" : vk=#VK_UP 
             EndSelect 
             If Left(s$,3)<>"ALT" And Left(s$,7)<>"CONTROL" And Left(s$,5)<>"SHIFT" 
                keybd_event_(vk,0,0,0) : keybd_event_(vk,0,#KEYEVENTF_KEYUP,0) ; Press the special key. 
             EndIf 
             r=r+s+1 ; Continue getting the keystrokes that follow the special key. 
          Else 
             vk=VkKeyScanEx_(Asc(vk$),GetKeyboardLayout_(0)) ; Normal key found. 
             If vk>304 And shifted=0 : keybd_event_(#VK_SHIFT,0,0,0) : EndIf ; Due to shifted character. 
             keybd_event_(vk,0,0,0) : keybd_event_(vk,0,#KEYEVENTF_KEYUP,0) ; Press the normal key. 
             If vk>304 And shifted=0 : keybd_event_(#VK_SHIFT,0,#KEYEVENTF_KEYUP,0) : EndIf ; Due to shifted character. 
          EndIf 
      Next 
      If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#FALSE) : EndIf ; Finished typing to target window! 
      keybd_event_(#VK_MENU,0,#KEYEVENTF_KEYUP,0) ; Release ALT key if user forgot. 
      keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0) ; Release CONTROL key if user forgot. 
      keybd_event_(#VK_SHIFT,0,#KEYEVENTF_KEYUP,0) ; Release SHIFT key if user forgot. 
      ProcedureReturn 1 ; Report successful typing! :) 
   EndIf 
EndProcedure 
; 
m$= "This example types some text to Notepad, then clears and closes it."+Chr(13) 
m$=m$+"Open a new Notepad window, then click the OK button and watch! :)" 
MessageRequester("SendKeys example",m$,#MB_ICONINFORMATION) 
; 
RunProgram("c:\winnt\notepad.exe","","",0) 
w$="Untitled - Notepad" ; Specifies target window name. 
Delay(1000) : SendKeys(0,w$,"This is a test!") ; Type some dummy text. 
Delay(1000) : SendKeys(0,w$,"{CONTROLDOWN}a{CONTROLUP}") ; Select it all. 
Delay(1000) : SendKeys(0,w$,"{DELETE}")      ; Delete it. 

Delay(1000) : SendKeys(0,w$,"{CONTROLDOWN}p{CONTROLUP}") 

;Delay(1000) : SendKeys(0,w$,"{ALTDOWN}{F4}") ; Close the Notepad Window
3e code

Code : Tout sélectionner

; Auteur : Inconnu
; Version de PB : 3.90
; 
; Explication du programme :
; Cette procedure permet de faire croire à l'application qui a le focus que l'on se sert du clavier.
; Dans cet exemple, je sélectionne le contenu du fichier ouvert dans l'éditeur PureBasic, copie le texte, crée un nouveau fichier puis colle le texte.

; Remarque : ne pas activer le débogueur sinon l'éditeur de PB n'aura pas le focus.

Procedure KeyBoardEvent(Touche, ToucheSpecial)
  ; 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
  
  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(20)
    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)

KeyBoardEvent(#PB_Shortcut_A, 1)
KeyBoardEvent(#PB_Shortcut_C, 1)
KeyBoardEvent(#PB_Shortcut_N, 1)
KeyBoardEvent(#PB_Shortcut_V, 1)
Voila, j'espere t'avoir dépanné, en attendant les "éléphants" du forum, tu vois, ce forum est tellement formidable, qu'ici on a des éléphants qui volent la nuit. :lol:
Bonne journée

Publié : dim. 14/oct./2007 11:00
par Backup
correction de ton 2em code qui télécommande le bloc note

en effet ton exemple est valable pour la version windows NT et la version anglaise du bloc notes

voici le même exemple pour la version Windows XP et sa version Française
du bloc note !! :)

pour rappel , ce prg montre comment on peut
1- ouvrir le bloc note
2- écrire dedans en simulant l'appui des touches du clavier

3- exécute une sélection du texte entré

4- propose l'impression du bloc note (cette ligne a été mise en commentaire)

5- quitte le bloc note :D

Code : Tout sélectionner


; Author: Danilo
; Date: 07. April 2003


; Posted 07 April 2003 by Danilo on german forum

;SendKeys(handel,Window$,Keys$)

;Handel ......... ist ein Handel zu einen Fenster bekommst du wenn du das Fenster erzeugst.
;Window$ ........ Ist der Name des Fesnters, wenn du den Handel nicht kennst. In dem Fall gibt man dan Handel = 0 an.
;Keys$ .......... Sind die Tasten die du schicken möchtest, wobei du Sondertasten in {} Einschliest (zb. {CONTROLDOWN})

; SendKeys procedure by PB -- do whatever you want with it. :)
; Syntax: r=SendKeys(handle,window$,keys$) ; r = 0 for failure.
; Specify either a handle or window$ title to type to, but not both!
; You cannot type curly braces { } as part of the keystrokes, sorry!
;

;
declare  SendKeys(handle,window$,keys$)

m$= "This example types some text to Notepad, then clears and closes it."+Chr(13)
m$=m$+"Open a new Notepad window, then click the OK button and watch! :)"
MessageRequester("SendKeys example",m$,#MB_ICONINFORMATION)
;
RunProgram("c:\windows\notepad.exe","","",0)
w$="Sans titre - Bloc-notes" ; Specifies target window name.
Delay(1000) : SendKeys(0,w$,"This is a test!") ; Type some dummy text.
Delay(1000) : SendKeys(0,w$,"{CONTROLDOWN}a{CONTROLUP}") ; Select it all.
Delay(1000) : SendKeys(0,w$,"{DELETE}")      ; Delete it.

;Delay(1000) : SendKeys(0,w$,"{CONTROLDOWN}p{CONTROLUP}")

Delay(1000) : SendKeys(0,w$,"{ALTDOWN}{F4}") ; Close the Notepad Window


; ****************************************************************************************
; ****************************************************************************************
; ************************ PROCEDURE ****************************************************
; ****************************************************************************************
; ****************************************************************************************



Procedure SendKeys(handle,window$,keys$)
    If window$<>"" : handle=FindWindow_(0,window$) : EndIf ; Use window$ instead of handle.
    If IsWindow_(handle)=0 ; Does the target window actually exist?
        ProcedureReturn 0 ; Nope, so report 0 for failure to type.
    Else
        ; This block gives the target window the focus before typing.
        thread1=GetWindowThreadProcessId_(GetForegroundWindow_(),0)
        thread2=GetWindowThreadProcessId_(handle,0)
        If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#True) : EndIf
        SetForegroundWindow_(handle) ; Target window now has the focus for typing.
        Delay(125) ; 1/8 second pause before typing, to prevent fast CPU problems.
        ; Now the actual typing starts.
        For r=1 To Len(keys$)
            vk$=Mid(keys$,r,1)
            If vk$="{" ; Special key found.
                s=FindString(keys$,"}",r+1)-(r+1) ; Get length of special key.
                s$=Mid(keys$,r+1,s) ; Get special key name.
                Select s$ ; Get virtual key code of special key.
                    Case "ALTDOWN" : keybd_event_(#VK_MENU,0,0,0) ; Hold ALT down.
                    Case "ALTUP" : keybd_event_(#VK_MENU,0,#KEYEVENTF_KEYUP,0) ; Release ALT.
                    Case "BACKSPACE" : vk=#VK_BACK
                    Case "CONTROLDOWN" : keybd_event_(#VK_CONTROL,0,0,0) ; Hold CONTROL down.
                    Case "CONTROLUP" : keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0) ; Release CONTROL.
                    Case "DELETE" : vk=#VK_DELETE
                    Case "DOWN" : vk=#VK_DOWN
                    Case "END" : vk=#VK_END
                    Case "ENTER" : vk=#VK_RETURN
                    Case "F1" : vk=#VK_F1
                    Case "F2" : vk=#VK_F2
                    Case "F3" : vk=#VK_F3
                    Case "F4" : vk=#VK_F4
                    Case "F5" : vk=#VK_F5
                    Case "F6" : vk=#VK_F6
                    Case "F7" : vk=#VK_F7
                    Case "F8" : vk=#VK_F8
                    Case "F9" : vk=#VK_F9
                    Case "F10" : vk=#VK_F10
                    Case "F11" : vk=#VK_F11
                    Case "F12" : vk=#VK_F12
                    Case "ESCAPE" : vk=#VK_ESCAPE
                    Case "HOME" : vk=#VK_HOME
                    Case "INSERT" : vk=#VK_INSERT
                    Case "LEFT" : vk=#VK_LEFT
                    Case "PAGEDOWN" : vk=#VK_NEXT
                    Case "PAGEUP" : vk=#VK_PRIOR
                    Case "PRINTSCREEN" : vk=#VK_SNAPSHOT
                    Case "RETURN" : vk=#VK_RETURN
                    Case "RIGHT" : vk=#VK_RIGHT
                    Case "SHIFTDOWN" : shifted=1 : keybd_event_(#VK_SHIFT,0,0,0) ; Hold SHIFT down.
                    Case "SHIFTUP" : shifted=0 : keybd_event_(#VK_SHIFT,0,#KEYEVENTF_KEYUP,0) ; Release SHIFT.
                    Case "TAB" : vk=#VK_TAB
                    Case "UP" : vk=#VK_UP
                EndSelect
                If Left(s$,3)<>"ALT" And Left(s$,7)<>"CONTROL" And Left(s$,5)<>"SHIFT"
                    keybd_event_(vk,0,0,0) : keybd_event_(vk,0,#KEYEVENTF_KEYUP,0) ; Press the special key.
                EndIf
                r=r+s+1 ; Continue getting the keystrokes that follow the special key.
            Else
                vk=VkKeyScanEx_(Asc(vk$),GetKeyboardLayout_(0)) ; Normal key found.
                If vk>304 And shifted=0 : keybd_event_(#VK_SHIFT,0,0,0) : EndIf ; Due to shifted character.
                keybd_event_(vk,0,0,0) : keybd_event_(vk,0,#KEYEVENTF_KEYUP,0) ; Press the normal key.
                If vk>304 And shifted=0 : keybd_event_(#VK_SHIFT,0,#KEYEVENTF_KEYUP,0) : EndIf ; Due to shifted character.
            EndIf
        Next
        If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#FALSE) : EndIf ; Finished typing to target window!
        keybd_event_(#VK_MENU,0,#KEYEVENTF_KEYUP,0) ; Release ALT key if user forgot.
        keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0) ; Release CONTROL key if user forgot.
        keybd_event_(#VK_SHIFT,0,#KEYEVENTF_KEYUP,0) ; Release SHIFT key if user forgot.
        ProcedureReturn 1 ; Report successful typing! :)
    EndIf
EndProcedure


Publié : dim. 14/oct./2007 11:22
par Kwai chang caine
Merci DOBRO.
Je suis rassuré, tu n'en a corrigé qu'un sur 3 donc, si mes calculs sont bons, je devrais avoir 12,xx/ 20. :D
C'est pas mal pour des debuts "d'aideur public" :lol:

"J'm'es" pas trop trompé alors :wink:

Publié : mer. 02/juil./2008 15:59
par Kwai chang caine
Sur le forum allemand, j'ai trouvé un code de SICRO qui gere aussi les caracteres ponctuation comme l'anti slash.
Car celui-ci remplace les "\" par des "8" 8O

Si ça peut etre utile :roll:
http://www.purebasic.fr/german/viewtopi ... 942#149551