Page 1 sur 1

Soucis de keyboardpushed

Publié : mar. 17/juil./2007 11:38
par Ar-S
Salut les coders,

J'ai un petit soucis, je suis en train de me faire une mini appli comportant que des boutons.
Certains boutons enclenchent un RunProgram (ici pas de soucis) mais d'autres sont censés simulé l'apye de touches.

Par exemple, je voudrais qu'en cliquant sur un bouton, PB simule l'appuye sur CTRL ALT SUPPR pour faire apparaitre le gestionaire de tâche..

Donc j'ai mis :

Code : Tout sélectionner

 ElseIf EventGadget = #BT_gesttache
        KeyboardPushed(#PB_Key_LeftControl)  And KeyboardPushed(#PB_Key_RightAlt) And KeyboardPushed(#PB_Key_Delete)
Je pige pas pourquoi ça ne fonctionne pas.

Nul doute que c'est un prob de syntaxe mais si vous pouviez m'éclairer :)

Seconde question. Quel est la syntaxe pour simuler l'appuye de la touche Windows (situé entre Alt gauche et Crtl gauche) ?

Merci
:P

Publié : mar. 17/juil./2007 12:02
par Anonyme

Code : Tout sélectionner

OpenConsole()
Repeat
  If GetAsyncKeyState_(#VK_CONTROL) And GetAsyncKeyState_(#VK_MENU) And GetAsyncKeyState_(#VK_DELETE)
    Print("A+B")
  EndIf
ForEver
Pour simuler l'appuis d'une touche, regarde du coté de SendMessage_()

Publié : mar. 17/juil./2007 12:08
par gnozal
Pour simuler l'appui sur une(des) touche(s) du clavier : http://www.purebasic.fr/english/viewtopic.php?t=3766

Ou dans CodeArchiv, répertoire 'Input+Output\Get&Send_Keys\'.

Peut-être qu'une adaptation est nécessaire pour certaines touches du clavier français mais çà fonctionne bien par ailleurs.

Par exemple :

Code : Tout sélectionner

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

;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

Re: Soucis de keyboardpushed

Publié : mar. 17/juil./2007 12:27
par gnozal
Ar-S a écrit :Quel est la syntaxe pour simuler l'appuye de la touche Windows (situé entre Alt gauche et Crtl gauche) ?
Trouvé çà avec Google :

Code : Tout sélectionner

VK_LWIN	5B	Left Windows key (Microsoft Natural Keyboard) 
VK_RWIN	5C	Right Windows key (Microsoft Natural Keyboard)
VK_APPS	5D	Applications key (Microsoft Natural Keyboard)

Publié : mar. 17/juil./2007 12:54
par Ar-S
Merci les amis,
je vais potacer ça dans l'aprés midi.

Publié : mar. 17/juil./2007 12:55
par brossden
Pour ce genre de commande j'utilise la lib Droopy qui pour moi fait partie integrantre de PureBasic !

Code : Tout sélectionner

CTrl  = 1
Alt   = 0
Shift = 0
Tempo = 1
SimulateKeyPress(#VK_A, Tempo, CTrl, Alt, Shift)
Je pense que ces quelques lignes se passent de commantaire !