Aide:HotKeySet.txt

De Wiki AutoIt Français
Aller à : navigation, rechercher

Document original V3.3.6.1 :

###Function###
HotKeySet

###Description###
Sets a hotkey that calls a user function.

###Syntax###
HotKeySet ( "key" [, "function"] )


###Parameters###
@@ParamTable@@
key
	The key combination to use as the hotkey. <b>Same format as <a href="Send.htm">Send()</a>.</b>
function
	[optional] The name of the function to call when the key is pressed. Not specifying this parameter will unset a previous hotkey.
@@End@@

###ReturnValue###
@@ReturnTable@@
Success:	Returns 1.
Failure:	Returns 0.
@@End@@


###Remarks###
If two AutoIt scripts set the same HotKeys, you should avoid running those scripts simultaneously.  (The second script cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting the hotkey.)

A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes or is interrupted.  Exceptions are as follows:
1)  If the current function is a "blocking" function, then the key-presses are buffered and execute as soon as the blocking function completes.  MsgBox and FileSelectFolder are examples of blocking functions.  Try the behavior of Shift-Alt-d in the Example.
2)  If you have paused the script by clicking on the AutoIt Tray icon, any hotkeys pressed during this paused state are ignored.

<b>The following hotkeys cannot be set:</b>

@@ParamTable@@
Ctrl+Alt+Delete
	It is reserved by Windows
F12
	It is also reserved by Windows, according to its API.
NumPad's Enter Key
	Instead, use {Enter} which captures both Enter keys on the keyboard.
Win+B,D,E,F,L,M,R,U; and Win+Shift+M
	These are built-in Windows shortcuts.  Note:  Win+B and Win+L might only be reserved on Windows XP and above.
Alt, Ctrl, Shift, Win
	These are the modifier keys themselves!
Other
	Any global hotkeys a user has defined using third-party software,  any combos of two or more "base keys" such as '{F1}{F2}', and any keys of the form '{LALT}' or '{ALTDOWN}'.
@@End@@
	
When you set a hotkey, AutoIt captures the key-press and does not pass it on to the active application, with one exception:  the Lock keys (NumLock, CapsLock, and ScrollLock) still toggle their respective state!
To Send() a key combination which will trigger a HotKeySet() event, either use ControlSend() or unregister the HotKeySet() event, otherwise, the Send() event may trigger an infinite loop.

; capture and pass along a keypress
<i>HotKeySet("{Esc}", "captureEsc")
Func captureEsc()
	; ... can do stuff here
	HotKeySet("{Esc}")
	Send("{Esc}")
	HotKeySet("{Esc}", "captureEsc")
EndFunc
</i>

The called function can <b>not</b> be given parameters. They will be ignored.

@HotKeyPressed macro can be used inside the function to handle several keys in the same function.


###Related###
Send, GUISetAccelerators


###Example###
@@IncludeExample@@


Document traduit V3.3.6.1 :

###Function###
HotKeySet

###Description###
Défini un raccourci clavier qui appel une fonction utilisateur.


###Syntax###
HotKeySet ( key [, function] )


###Parameters###
@@ParamTable@@
key
	La combinaison de touches à utiliser comme raccourci clavier. <b>Même format que <a href="Send.htm">Send()</a>.</b>
	[optionnel] Le nom de la fonction à appeler lorsque la touche est appuyée. Si cette valeur n'est pas spécifié, le raccourci précédemment créé est effacé.
@@End@@


###ReturnValue###
@@ReturnTable@@
Succès:	Retourne 1.
Échec:	Retourne 0.


###Remarks###
Si deux scripts AutoIt définissent un même raccourci clavier, vous ne devriez pas lancer ces scripts simultanément. (Le second script ne pourra pas capturer le raccourci clavier, tant que le premier script ne sera pas terminé, ou que le premier raccourci soit effacé avant que le second script ne définisse le sien).

L'appui sur un raccourci clavier interrompt généralement la fonction ou la condition en cours dans le script, et exécute la fonction définie jusqu'à ce que celle-ci se termine ou qu'elle soit interrompue. Les exceptions sont les suivantes :
1) Si la fonction en cours est une fonction "bloquante", l'appui sur le raccourci clavier est mis en attente puis traité dès que la fonction bloquante se termine. MsgBox et FileSelectFolder sont des exemples de fonctions bloquantes. Essayez le comportement de Shift-Alt-d dans l'exemple.
2) Si vous avez mis le script en pause par un clic sur l'icône AutoIt de la barre des tâches, tous les raccourcis clavier appuyés pendant cette pause sont ignorés.

<b>Les combinaisons suivantes ne peuvent pas être attribuées :</b>

@@ParamTable@@
Ctrl+Alt+Delete
	Raccourci réservé par Windows.
F12
	Raccourci également réservé à Windows, selon son API.
"Entrée" (pavé numérique)
	A la place, utilisez {Enter} qui capture les deux touches "Entrée" du clavier.
Win+B,D,E,F,L,M,R,U; et Win+Shift+M
	Ce sont des raccourcis intégrés à Windows.  Note:  Win+B et Win+L sont probablement réservés sur Windows XP et supérieur.
Alt, Ctrl, Shift, Win
	Ce sont les touches de modification elles mêmes !
Autres
	Tout raccourci clavier global qu'un utilisateur a défini par une application tierce, et toute combinaison de deux "touches de base" ou plus telle que '{F1}{F2}' et n'importe qu'elle touche de la forme '{LALT}' ou '{ALTDOWN}'.
@@End@@

Lorsque vous définissez un raccourci clavier, AutoIt capture les appuis de touche sans les faire passer à l'application active en cours, avec une exception :  les touches de verrouillage (NumLock, CapsLock, et ScrollLock) basculeront toujours leur état respectif !
Pour envoyer une combinaison de touches qui déclenchera un événement HotKeySet(), utilisez ControlSend() au lieu de Send(), ou dés-enregistrez l'événement HotKeySet(), sinon, l'événement Send() provoquera une boucle infinie.

; capture et envoi d'un appui de touche
<i>HotKeySet("{Esc}", "captureEsc")
Func captureEsc()
	; ... peut faire des actions ici
	HotKeySet("{Esc}")
	Send("{Esc}")
	HotKeySet("{Esc}", "captureEsc")
EndFunc
</i>

La fonction appelée <b>ne peut pas</b> recevoir de paramètres. Ils seront ignorés.

La macro @HotKeyPressed peut être utilisée à l'intérieur de la fonction pour traiter différentes touches dans la même fonction.

###Related###
<a href="Send.htm">Send</a>, <a href="GUISetAccelerators.htm">GUISetAccelerators</a>


###Example###
@@IncludeExample@@


Traducteur : ZDS

Contributeurs (pour les modifications avant le Wiki) : Tlem