« AutoHotKey » : différence entre les versions

De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications
 
 
(28 versions intermédiaires par le même utilisateur non affichées)
Ligne 4 : Ligne 4 :
[http://fincs.ahk4.net/scite4ahk SciTE4AutoHotkey] permet d'avoir la coloration syntaxique avec les fichiers ahk.
[http://fincs.ahk4.net/scite4ahk SciTE4AutoHotkey] permet d'avoir la coloration syntaxique avec les fichiers ahk.


= Liens =
= Links =
* [https://autohotkey.com/docs/Variables.htm#BuiltIn Built-in Variables]
* [https://autohotkey.com/docs/Variables.htm#BuiltIn Built-in Variables]
* [https://www.autohotkey.com/docs/KeyList.htm List of Keys]


= [http://www.autohotkey.com/docs/commands/Send.htm Send] =
= [http://www.autohotkey.com/docs/commands/Send.htm Send] =
Ligne 29 : Ligne 30 :
|-
|-
| <^>! || Alt Gr
| <^>! || Alt Gr
|-
| * || Wildcard: Fire the hotkey even if extra modifiers are being held down.
|-
| $ || This is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which might otherwise cause it to trigger itself.
|}
|}
{{info | Si une combinaison ne fonctionne pas avec {{boxx|+}} essayez la forme: {{boxx|Shift & key::Send {key} }}}}
{{info | Si une combinaison ne fonctionne pas avec {{boxx|+}} essayez la forme: {{boxx|Shift & key::Send {key} }}}}
{{info | Pour les [http://www.autohotkey.com/docs/commands/_EscapeChar.htm caractères spéciaux] comme {{boxx|%}} → {{boxx|key::Send `%}}}}
{{info | Pour les [http://www.autohotkey.com/docs/commands/_EscapeChar.htm caractères spéciaux] comme {{boxx|%}} → {{boxx|key::Send `%}}}}
{{info | {{boxx|$}} is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which might otherwise cause it to trigger itself. }}


= Capture de la Souris =
= Capture de la Souris =
Ligne 50 : Ligne 55 :


== Double-clique ==
== Double-clique ==
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
; Double click
; Double click
~LButton::  
~LButton::  
Ligne 59 : Ligne 64 :


= [http://www.autohotkey.com/docs/commands/MouseClick.htm Générer des événements souris] =
= [http://www.autohotkey.com/docs/commands/MouseClick.htm Générer des événements souris] =
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
; Clique gauche
; Clique gauche
MouseClick, left
MouseClick, left
Ligne 68 : Ligne 73 :


= [http://www.autohotkey.com/docs/commands/_IfWinActive.htm Mapping pour une application spécifique] =
= [http://www.autohotkey.com/docs/commands/_IfWinActive.htm Mapping pour une application spécifique] =
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
; Si LibreOffice est actif, mapper le point du pavé numérique avec le point et non la virgule par défaut en FR
; Si LibreOffice est actif, mapper le point du pavé numérique avec le point et non la virgule par défaut en FR
IfWinActive ahk_class SALFRAME
IfWinActive ahk_class SALFRAME
Ligne 84 : Ligne 89 :


= Désactiver / remapper les touches Caps Lock, Num Lock, Scroll Lock =
= Désactiver / remapper les touches Caps Lock, Num Lock, Scroll Lock =
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
; set the default state of the lock keys
; set the default state of the lock keys
SetCapsLockState, off
SetCapsLockState, off
Ligne 99 : Ligne 104 :


= [http://www.autohotkey.com/docs/commands/IfExpression.htm if else] =
= [http://www.autohotkey.com/docs/commands/IfExpression.htm if else] =
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
if Variable
if Variable
     ...
     ...
Ligne 110 : Ligne 115 :


= Lire et écrire dans un fichier =
= Lire et écrire dans un fichier =
<kode lang='AutoHotkey'>
<kode lang='ahk'>
; écriture dans %USERPROFILE%\AppData\Local\Temp\file.tmp
; écriture dans %USERPROFILE%\AppData\Local\Temp\file.tmp
"text" > %A_Temp%\file.tmp
"text" > %A_Temp%\file.tmp
Ligne 124 : Ligne 129 :


= Exécuter du code PowerShell, Batch =
= Exécuter du code PowerShell, Batch =
<kode lang='AutoHotkey'>
<kode lang='ahk'>
; Batch, écriture du résultat dans %USERPROFILE%\AppData\Local\Temp\result.tmp
; Batch, écriture du résultat dans %USERPROFILE%\AppData\Local\Temp\result.tmp
RunWait %Comspec% /c "commande batch" > %A_Temp%\result.tmp,,HIDE
RunWait %Comspec% /c "commande batch" > %A_Temp%\result.tmp,,HIDE
Ligne 133 : Ligne 138 :
[https://autohotkey.com/docs/commands/Run.htm Run]
[https://autohotkey.com/docs/commands/Run.htm Run]


= ScanCode =
= [https://www.autohotkey.com/docs/KeyList.htm#other ScanCode] =
Clique-droit sur l'icone → Open → View → Key history and script info<br>
Clique-droit sur l'icone → Open → View (Menu bar) → Key history and script info<br>
Appuyer sur une touche → F5<br>
Appuyer sur une touche → F5<br>
Le code de la 2ème colonne correspond au ScanCode
Le code de la 2ème colonne correspond au ScanCode
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
 
SC02D::MsgBox, %A_ThisHotKey% was pressed.  ; x
{| class="wikitable wtp"
! VK
! SC
! Type
! Up/Dn
! Elapsed
! Key
! Window
|-
| C0 || 01B || h || d|| 1.72 || ¨ ||
|}
 
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
*VKC0::! ; ¨ → !
$+VKC0::send {U+00A8} ; shift + ¨ (!) → ¨
$<^>!VKC0::] ; AltGr + ¨ → ]
</filebox>
</filebox>


= Exemples =
= Exemples =
<kode lang=AutoHotkey>
<kode lang=ahk>
; ctrl-w -> ctrl-z
; ctrl-w -> ctrl-z
^w::^z
^w::^z
Ligne 171 : Ligne 191 :


== [http://www.ilovefreesoftware.com/30/tutorial/auto-copy-selected-text-clipboard-windows-10.html Copie la sélection dans le presse-papier] ==
== [http://www.ilovefreesoftware.com/30/tutorial/auto-copy-selected-text-clipboard-windows-10.html Copie la sélection dans le presse-papier] ==
<kode lang=AutoHotkey collapsed>
<kode lang=ahk collapsed>
~Lshift::
~Lshift::
TimeButtonDown = %A_TickCount%
TimeButtonDown = %A_TickCount%
Ligne 306 : Ligne 326 :


=== Old ===
=== Old ===
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey collapsed>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk collapsed>
CopyToClipboard2()
CopyToClipboard2()
{
{
Ligne 363 : Ligne 383 :


== [https://www.autohotkey.com/docs/Hotkeys.htm#AltTabDetail Alt Tab] ==
== [https://www.autohotkey.com/docs/Hotkeys.htm#AltTabDetail Alt Tab] ==
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
; AltTab avec Ctrl + Backspace
; AltTab avec Ctrl + Backspace
ctrl & backspace::AltTab
ctrl & backspace::AltTab
</filebox>
</filebox>


<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
; AltTab avec CapsLock
; AltTab avec CapsLock
CapsLock::AltTabAndMenu
CapsLock::AltTabAndMenu
Ligne 382 : Ligne 402 :


== Contrôle du son avec la molette ==
== Contrôle du son avec la molette ==
<kode lang=AutoHotkey>
<kode lang=ahk>
+WheelUp::Send {Volume_Up 1}
!WheelUp::Send "{Volume_Up 1}"
+WheelDown::Send {Volume_Down 1}
!WheelDown::Send "{Volume_Down 1}"
</kode>
</kode>


== Verrouiller ==
== Verrouiller ==
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
; Windows + Esc
; Windows + Esc
#Escape::DllCall("LockWorkStation")
#Escape::DllCall("LockWorkStation")
Ligne 394 : Ligne 414 :


== Print Screen ==
== Print Screen ==
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
; Lancer SnippingTool avec la touche Print Screen
; Lancer SnippingTool avec la touche Print Screen
PrintScreen::Run SnippingTool.exe
PrintScreen::Run SnippingTool.exe
Ligne 400 : Ligne 420 :


== Mot de passe sous Windows ==
== Mot de passe sous Windows ==
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=AutoHotkey>
<filebox fn="C:\Windows\System32\drivers\etc\AutoHotkey.ahk" lang=ahk>
#a::
#a::
RunWait, powershell.exe "pm get key1" | Set-Content -NoNewline %A_Temp%\pm.tmp,,HIDE
RunWait, powershell.exe "pm get key1" | Set-Content -NoNewline %A_Temp%\pm.tmp,,HIDE
Ligne 481 : Ligne 501 :


[[PowerShell#Stocker_et_r.C3.A9cup.C3.A9rer_un_mot_de_passe|Stocker et récupérer un mot de passe]]
[[PowerShell#Stocker_et_r.C3.A9cup.C3.A9rer_un_mot_de_passe|Stocker et récupérer un mot de passe]]
== Switch Shift for number keys ==
<kode lang='ahk' collapsed>
#requires AutoHotkey v2.0
1::+
2::"
3::*
4::ç ; send "{U+00E7}"
5::%
6::&
7::/
8::(
9::)
0::=
+1::send 1
+2::send 2
+3::send 3
+4::send 4
+5::send 5
+6::send 6
+7::send 7
+8::send 8
+9::send 9
+0::send 0
; allow Ctrl+N to send Ctrl+N instead of Ctrl+Shift+N
^1::^1
^2::^2
^3::^3
^4::^4
^5::^5
^6::^6
^7::^7
^8::^8
^9::^9
^0::^0
<^>!1::|
<^>!2::@
<^>!3::#
<^>!4::Ç
<^>!5::send "{U+2030}" ; ‰
<^>!7::|
<^>!0::send "{U+2260}" ; ≠
$^::send "{U+0060}" ; `
+^::^ ; send "{U+005E}"
<^>!^::send "{U+223C}" ; ∼
-::_
+-::-
<^>!-::send "{U+2192}" ; →
;;; CH keyboard
ä::À
ö::É
ü::È
VKC0::!
+VKC0::¨ ; send "{U+00A8}"
<^>!VKC0::]
VKBF::send "{BackSpace}" ; §
+VKBF::send "{Delete}" ; °
;;; CH keyboard
</kode>


= Installation =
= Installation =

Dernière version du 6 mars 2024 à 14:39

Généralités

AutoHotKey
SciTE4AutoHotkey permet d'avoir la coloration syntaxique avec les fichiers ahk.

Links

Send

Send les caractères spéciaux sont transformés
SendRaw pas de transformation, envoie les caractères tels qu'ils sont écrits
SendInput plus rapide et plus fiable que Send
SendPlay similaire à SendInput, mais plus adapté pour les jeux vidéo

Clavier

# Windows
! Alt
^ Ctrl
+ Shift
<^>! Alt Gr
* Wildcard: Fire the hotkey even if extra modifiers are being held down.
$ This is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which might otherwise cause it to trigger itself.
Si une combinaison ne fonctionne pas avec + essayez la forme: Shift & key::Send {key}
Pour les caractères spéciaux comme %key::Send `%

Capture de la Souris

LButton clique gauche
RButton clique droit
MButton clique roulette
XButton1 bouton 4 (doit être assigné à Browser_Back)
XButton2 bouton 5 (doit être assigné à Browser_Forward)
XButton3 n'est pas implémenté car Windows ne supporte que 5 boutons.
Il faut donc mapper ce 6ème boutons à une combinaison de touches et remapper ces touches à une action.

Double-clique

C:\Windows\System32\drivers\etc\AutoHotkey.ahk
; Double click
~LButton:: 
If (A_TimeSincePriorHotkey<400) and (A_PriorHotkey="~LButton")
	MsgBox You double Left clicked on something 
Return

Générer des événements souris

C:\Windows\System32\drivers\etc\AutoHotkey.ahk
; Clique gauche
MouseClick, left

; Double clique
MouseClick, left, , , 2

Mapping pour une application spécifique

C:\Windows\System32\drivers\etc\AutoHotkey.ahk
; Si LibreOffice est actif, mapper le point du pavé numérique avec le point et non la virgule par défaut en FR
IfWinActive ahk_class SALFRAME
NumPadDot::SendInput .

; Si Firefox ou Notepad++ est actif
If WinActive("ahk_class MozillaWindowClass") or WinActive("ahk_class Notepad++") { }

; A window's title can contain WinTitle anywhere inside it to be a match.
SetTitleMatchMode, 2

SetTitleMatchMode

Par défaut, l'expression doit correspondre au début du titre de la fenêtre.
Si ahk_class est spécifié, l'expression doit correspondre exactement à la classe de la fenêtre.

Désactiver / remapper les touches Caps Lock, Num Lock, Scroll Lock

C:\Windows\System32\drivers\etc\AutoHotkey.ahk
; set the default state of the lock keys
SetCapsLockState, off
SetNumLockState, on
SetScrollLockState, off

; disable them
$NumLock::Return
$ScrollLock::Return

; make the capslock key behave as menu/AppsKey
CapsLock::AppsKey

if else

C:\Windows\System32\drivers\etc\AutoHotkey.ahk
if Variable
    ...
else if (x > y) {
   ...
   ...
} else
   ...

Lire et écrire dans un fichier

Ahk.svg
; écriture dans %USERPROFILE%\AppData\Local\Temp\file.tmp
"text" > %A_Temp%\file.tmp
; écriture sans saut de ligne
"text" | Set-Content -NoNewline %A_Temp%\file.tmp

; lecture du fichier %USERPROFILE%\AppData\Local\Temp\file.tmp
FileRead, FileContent, %A_Temp%\file.tmp
; lecture de la ligne 1
FileReadLine, FileLineOne, %A_Temp%\file.tmp, 1

FileRead, FileReadLine

Exécuter du code PowerShell, Batch

Ahk.svg
; Batch, écriture du résultat dans %USERPROFILE%\AppData\Local\Temp\result.tmp
RunWait %Comspec% /c "commande batch" > %A_Temp%\result.tmp,,HIDE

; PowerShell, écriture du résultat dans %USERPROFILE%\AppData\Local\Temp\result.tmp
RunWait powershell.exe "commande powershell" > %A_Temp%\result.tmp,,HIDE

Run

ScanCode

Clique-droit sur l'icone → Open → View (Menu bar) → Key history and script info
Appuyer sur une touche → F5
Le code de la 2ème colonne correspond au ScanCode

VK SC Type Up/Dn Elapsed Key Window
C0 01B h d 1.72 ¨
C:\Windows\System32\drivers\etc\AutoHotkey.ahk
*VKC0::! ; ¨ → !
$+VKC0::send {U+00A8} ; shift + ¨ (!) → ¨
$<^>!VKC0::] ; AltGr + ¨ → ]

Exemples

Ahk.svg
; ctrl-w -> ctrl-z
^w::^z
; ctrl-q -> ctrl-a
^q::^a

$F1::Send ^c ; copy
$F2::Send ^v ; paste

F12::Send !{F4} ; fermer fenêtre avec F12

; clique-milieu -> clique gauche + ctrl-v
MButton::
MouseClick
SendInput ^v
Return

; Alt-A select the whole line
!a::
Send {Home}
Send +{End}
Return

; dans LibreOffice
#IfWinActive ahk_class SALFRAME
NumPadDot::SendInput .

Copie la sélection dans le presse-papier

Ahk.svg
~Lshift::
TimeButtonDown = %A_TickCount%
; Wait for it to be released
Loop
{
	Sleep 10
	GetKeyState, LshiftState, Lshift, P
	if LshiftState = U  ; Button has been released.
		break
	elapsed = %A_TickCount%
	elapsed -= %TimeButtonDown%
	if elapsed > 200  ; Button was held down long enough
	{
		x0 = A_CaretX
		y0 = A_CaretY
		Loop
		{
			Sleep 20                    ; yield time to others
			GetKeyState keystate, Lshift
			IfEqual keystate, U, {
				x = A_CaretX
				y = A_CaretY
				break
			}
		}
		if (x-x0 > 5 or x-x0 < -5 or y-y0 > 5 or y-y0 < -5)
		{                             ; Caret has moved
			clip0 := ClipBoardAll      ; save old clipboard
			;ClipBoard =
			Send ^c                    ; selection -> clipboard
			ClipWait 1, 1              ; restore clipboard if no data
			IfEqual ClipBoard,, SetEnv ClipBoard, %clip0%
		}
		return
	}
}

~LButton::
MouseGetPos, xx
TimeButtonDown = %A_TickCount%
; Wait for it to be released
Loop
{
	Sleep 10
	GetKeyState, LButtonState, LButton, P
	if LButtonState = U  ; Button has been released.
	{
		If WinActive("Crimson Editor") and (xx < 25) ; Single Click in the Selection Area of CE
		{
			Send, ^c
			return
		}
		break
	}
	elapsed = %A_TickCount%
	elapsed -= %TimeButtonDown%
	if elapsed > 200  ; Button was held down too long, so assume it's not a double-click.
	{
		MouseGetPos x0, y0            ; save start mouse position
		Loop
		{
			Sleep 20                    ; yield time to others
			GetKeyState keystate, LButton
			IfEqual keystate, U, {
				MouseGetPos x, y          ; position when button released
				break
			}
		}
		if (x-x0 > 5 or x-x0 < -5 or y-y0 > 5 or y-y0 < -5)
		{                              ; mouse has moved
			clip0 := ClipBoardAll      ; save old clipboard
			;ClipBoard =
			Send ^c                    ; selection -> clipboard
			ClipWait 1, 1              ; restore clipboard if no data
			IfEqual ClipBoard,, SetEnv ClipBoard, %clip0%
		}
		return
	}
}

; Otherwise, button was released quickly enough. Wait to see if it's a double-click
TimeButtonUp = %A_TickCount%
Loop
{
	Sleep 10
	GetKeyState, LButtonState, LButton, P
	; Button has been pressed down again.
	if LButtonState = D
		break
	elapsed = %A_TickCount%
	elapsed -= %TimeButtonUp%
	; No click has occurred within the allowed time, so assume it's not a double-click.
	if elapsed > 350
		return
}

; Button pressed down again, it's at least a double-click
TimeButtonUp2 = %A_TickCount%
Loop
{
	Sleep 10
	GetKeyState, LButtonState2, LButton, P
	; Button has been released a 2nd time, let's see if it's a tripple-click.
	if LButtonState2 = U
		break
}

; Button released a 2nd time
TimeButtonUp3 = %A_TickCount%
Loop
{
	Sleep 10
	GetKeyState, LButtonState3, LButton, P
	if LButtonState3 = D  ; Button has been pressed down a 3rd time.
		break
	elapsed = %A_TickCount%
	elapsed -= %TimeButtonUp%
	if elapsed > 350  ; No click has occurred within the allowed time, so assume it's not a tripple-click.
	{  ;Double-click
		Send, ^c
		return
	}
}

; Tripple-click
Sleep, 100
Send, ^c
return

; Ctl+A = Select All, then Copy
~^a::Send, ^c

Old

C:\Windows\System32\drivers\etc\AutoHotkey.ahk
CopyToClipboard2()
{
	ClipSaved := ClipboardAll 		; Save the entire clipboard to a variable of your choice.
	Send ^c               			; Copy the highlighted text to the clipboard 
	ClipWait, 2				; Wait for the clipboard to contain text.
	if ErrorLevel
	{
		MsgBox, The attempt to copy text onto the clipboard failed.
		return
	}
	;MsgBox Control-C copied the following contents to the clipboard:`nüClipboardü
	global SecondClipboard
	SecondClipboard := Clipboard	    ; Assign the clipboard content to the variable 
	sleep, 100
	Clipboard := ClipSaved    	    ; Restore the original clipboard
	ClipSaved :=             	    ; Free the memory in case the clipboard was very large 
}

~LButton::
if not (WinActive("ahk_class CabinetWClass") or WinActive("ahk_class Shell_TrayWnd") or WinActive("ahk_class Progman"))
{
	MouseGetPos, cos_mousedrag_x, cos_mousedrag_y
	KeyWait LButton
	MouseGetPos, cos_mousedrag_x2, cos_mousedrag_y2
	if (abs(cos_mousedrag_x2 - cos_mousedrag_x) > 10 or abs(cos_mousedrag_y2 - cos_mousedrag_y) > 10)
	{
		CopyToClipboard2()
	}
	else if (A_TimeSincePriorHotkey < 400) and (A_PriorHotkey = "~LButton")
	{
		if (A_TimeSincePriorHotkey < 400) and (A_PriorHotkey = "~LButton")
		{
			;MsgBox You triple Left clicked on something 
			CopyToClipboard2()
		}
		else
		{
			;MsgBox You double Left clicked on something		
			CopyToClipboard2()
		}
	}
}
Return

XButton2::
StringReplace, SecondClipboard, SecondClipboard, `r, , All
;SendInput {LButton}
SendInput {Click left}
SendInput {Raw}üSecondClipboardü	; plus rapide que Send et SendRaw
Return

Alt Tab

C:\Windows\System32\drivers\etc\AutoHotkey.ahk
; AltTab avec Ctrl + Backspace
ctrl & backspace::AltTab
C:\Windows\System32\drivers\etc\AutoHotkey.ahk
; AltTab avec CapsLock
CapsLock::AltTabAndMenu
!LButton::    ; The ! prefix makes it fire while the Alt key is down (which it is if the alt-tab menu is visible).
	MouseClick, left
        Send {Alt up}
return
!Enter::
	Send {Enter}
	Send {Alt up}
return

Contrôle du son avec la molette

Ahk.svg
!WheelUp::Send "{Volume_Up 1}"
!WheelDown::Send "{Volume_Down 1}"

Verrouiller

C:\Windows\System32\drivers\etc\AutoHotkey.ahk
; Windows + Esc
#Escape::DllCall("LockWorkStation")

Print Screen

C:\Windows\System32\drivers\etc\AutoHotkey.ahk
; Lancer SnippingTool avec la touche Print Screen
PrintScreen::Run SnippingTool.exe

Mot de passe sous Windows

C:\Windows\System32\drivers\etc\AutoHotkey.ahk
#a::
RunWait, powershell.exe "pm get key1" | Set-Content -NoNewline %A_Temp%\pm.tmp,,HIDE
FileReadLine, Result, %A_Temp%\pm.tmp, 1
FileDelete, %A_Temp%\pm.tmp
SendRaw %Result%
SendInput {Enter}
Return
%UserProfile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
New-Alias pm "C:\Users\[USER]\Documents\WindowsPowerShell\Scripts\PasswordsManager.ps1"
C:\Users\[USER]\Documents\WindowsPowerShell\Scripts\PasswordsManager.ps1
[CmdletBinding()]
Param (
  [string] $Action = "help",
  [string] $Key
)

$PasswordFilesPath = "$home\passwords"

switch ($Action)
{
    "help"
    {
        "Password Manager:
        
> pm store <key>
> pm get <key>
> pm list"
    }
    "store"
    {
        if ([String]::IsNullOrEmpty($Key))
        {
            "Merci de renseigner une clé pour le stockage du mot de passe."
        }
        else
        {
            $Credential = Get-Credential -Message "Enter password for $Key" -Username "-"
            $SecurePassword = $Credential.Password
            $SecureStringAsPlainText = $SecurePassword | ConvertFrom-SecureString
            
            $FilePath = Join-Path "$PasswordFilesPath" "$Key.txt"
            Set-Content $FilePath $SecureStringAsPlainText
            "Mot de passe enregistré pour la clé $Key."
        }
    }
    "get"
    {
        $FilePath = Join-Path "$PasswordFilesPath" "$Key.txt"
        if ([String]::IsNullOrEmpty($Key))
        {
            "Merci de renseigner une clé pour le récupération du mot de passe."
        }
        elseif (Test-Path("$FilePath"))
        {
            $SecureStringAsPlainText = Get-Content "$FilePath"
            $SecurePassword = $SecureStringAsPlainText | ConvertTo-SecureString
            $Credential = New-Object PSCredential "-", $SecurePassword
            $PlainPassword = $Credential.GetNetworkCredential().Password
            $PlainPassword
        }
        else
        {
            "La clé $Key ne correspond à aucun mot de passe."
        }
    }
    "list"
    {
        #"Stored passwords:
        #"
        ls $PasswordFilesPath | % BaseName
    }
    default { "$Action is not a valid parameter." }
}

Stocker et récupérer un mot de passe

Switch Shift for number keys

Ahk.svg
#requires AutoHotkey v2.0

1::+
2::"
3::*
4::ç ; send "{U+00E7}"
5::%
6::&
7::/
8::(
9::)
0::=

+1::send 1
+2::send 2
+3::send 3
+4::send 4
+5::send 5
+6::send 6
+7::send 7
+8::send 8
+9::send 9
+0::send 0

; allow Ctrl+N to send Ctrl+N instead of Ctrl+Shift+N
^1::^1
^2::^2
^3::^3
^4::^4
^5::^5
^6::^6
^7::^7
^8::^8
^9::^9
^0::^0

<^>!1::|
<^>!2::@
<^>!3::#
<^>!4::Ç
<^>!5::send "{U+2030}" ; ‰
<^>!7::|
<^>!0::send "{U+2260}" ; ≠

$^::send "{U+0060}" ; `
+^::^ ; send "{U+005E}"
<^>!^::send "{U+223C}" ; ∼

-::_
+-::-
<^>!-::send "{U+2192}" ; →

;;; CH keyboard
ä::À
ö::É
ü::È

VKC0::!
+VKC0::¨ ; send "{U+00A8}"
<^>!VKC0::]

VKBF::send "{BackSpace}" ; §
+VKBF::send "{Delete}" ; °
;;; CH keyboard

Installation

  1. après l'installation, redémarrer pour mettre à jour le menu contextuel New
  2. créer un script: clique-droit dans un dossier → NewAutoHotkey Script
  3. modifier le script
  4. double-cliquer sur le fichier pour l'associer, l’icône AutoHotKey apparaît dans la zone de notification

Exécuter un script au démarrage

  1. Copier le script
  2. Coller le raccourci (Paste shortcut) dans %AppData%\Microsoft\Windows\Start Menu\Programs\Startup

Exécuter AutoHotKey au démarrage

  • Menu Start → AutoHotKey → copier le raccourci
  • Coller le raccourci (Paste shortcut) dans %AppData%\Microsoft\Windows\Start Menu\Programs\Startup

Définir Notepad++ comme éditeur par défaut

HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command
(Default) = "C:\Program Files\Notepad++\notepad++.exe" "%1"

Coloration syntaxique

  1. Language → Define your language → Import → Notepad++ AutoHotKey Syntax Highlighting Dark.xml
  2. redémarrer