Bonjour,
Sous Windows 11, comment peut-on commander par VBscript ou autre la touche Verrouille Nombres ?
Comment sous VB6 peut-on savoir si Verrouille Nombres est On ou Off ?
Cordialement,
-Valp47
Bonjour,
Sous Windows 11, comment peut-on commander par VBscript ou autre la touche Verrouille Nombres ?
Comment sous VB6 peut-on savoir si Verrouille Nombres est On ou Off ?
Cordialement,
-Valp47
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) Sub NumLock() ''Active NumLock Const VK_NUMLOCK = &H90, KEYEVENTF_EXTENDEDKEY = &H1, KEYEVENTF_KEYUP = &H2 If NumLockActivé Then Exit Sub keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0 keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0 End Sub Function NumLockActivé() ''Renvoie si NumLock est ON NumLockActivé = (GetKeyState(&H90) > 0) End Function
Check_NumLock_Status.vbs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 Option Explicit Dim Title,pscommand,strcmd,strOutput,strResult Title = "Check NumLock ON/OFF" pscommand = "write-host $([console]::NumberLock)" strcmd = "cmd /c powershell -C " & pscommand CreateObject("WScript.Shell").Run strcmd & " | clip", 0, True strOutput = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text") strResult = Replace(strOutput,vbCrlf,"") If Lcase(strResult) = "true" Then ' NumLock Already ON. MsgBox "The NUMLOCK is ON",vbInformation+vbSystemModal,Title Else ' NumLock is Off MsgBox "The NUMLOCK is OFF",vbInformation+vbSystemModal,Title CreateObject("WScript.Shell").SendKeys "{NUMLOCK}" End If![]()
Il me semble que cela renvoie le Presse-papier et rien de plus.
Code : Sélectionner tout - Visualiser dans une fenêtre à part strOutput = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")
D'autre part SendKeys "{NUMLOCK}" ne marche pas vraiment, est aléatoire.
Cordialement
Il va capturer la commande en powershell qui va nous retourner True ou bien False suivant l'état de votre NumLock et la stocke dans le presse-papier
Avez-vous testé ou pas encore sous windows 11, car chez moi (Windows 10) marche 5/5![]()
Voici une autre méthode avec redirection vers un fichier temporaire (Testé sur un Windows 10 64 bits)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 Option Explicit Dim Title,pscommand,strcmd,strOutput,strResult,AnswerQuestion Title = "Check NumLock ON/OFF" ' Commande Powershell pour retourner True ou bien False de l'état de NumLock pscommand = "write-host $([console]::NumberLock)" strcmd = "cmd /c powershell -C " & pscommand With CreateObject("WScript.Shell") ' Passez 0 comme deuxième paramètre pour masquer la fenêtre... .Run strcmd &" >.\out.txt", 0, True End With ' Lisez la sortie et supprimez le fichier lorsque vous avez terminé... With CreateObject("Scripting.FileSystemObject") strOutput = .OpenTextFile(".\out.txt").ReadLine() .DeleteFile ".\out.txt" End With strResult = Replace(strOutput,vbLf,"") wscript.echo chr(34) & strResult & chr(34) If Lcase(strResult) = "true" Then ' NumLock Already ON. MsgBox "The NUMLOCK is ON",vbInformation+vbSystemModal,Title Else ' NumLock is Off MsgBox "The NUMLOCK is OFF",vbExclamation+vbSystemModal,Title AnswerQuestion = MsgBox("Le NumLock est OFF !" & vbCrlf &_ "Voulez-vous l'activer ?",vbQuestion+vbYesNo+vbSystemModal,Title) If AnswerQuestion = vbYes Then CreateObject("WScript.Shell").SendKeys "{NUMLOCK}" Else MsgBox "The NUMLOCK is still OFF",vbExclamation+vbSystemModal,Title End If End If
J'ai testé sous Windows et cela me renvoie le contenu du Presse-papiers, comme la fonction l'implique.
Comment cela pourrait "capturer la commande en powershell" me paraît mystérieux (et quelle commande ?)
Cordialement
Partager