IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

detecter si le user est encore actif


Sujet :

Windows Forms

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de salihovic
    Inscrit en
    Février 2007
    Messages
    255
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 255
    Par défaut detecter si le user est encore actif
    salut
    j'ai besoin d'une méthode qui me permet de savoir si un utlisateur est encotr actif sur le pc
    par exemple par l'évennement de la souris ou du clavier
    (comme dans le cas de veille si l'utilisateur ne touche pas la souris ou le clavier une période (par exemple 2 mn) l'ordinateur entre en veille
    merci pour l'aide

  2. #2
    Rédacteur
    Avatar de Louis-Guillaume Morand
    Homme Profil pro
    Cloud Architect
    Inscrit en
    Mars 2003
    Messages
    10 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Cloud Architect
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2003
    Messages : 10 839
    Par défaut
    à toi d'écouter les messages de la souris et claviers (pinvoke) et d'implémenter ton timer que tu reset à chaque fois

  3. #3
    Membre éclairé Avatar de salihovic
    Inscrit en
    Février 2007
    Messages
    255
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 255
    Par défaut
    donc comment ça se fait?
    il faut a chaque foi entendre la souris et le clavier dans les evennement mouse move ou comment?
    on passe par les api?
    j'ai aucune idée.
    quelle DLL je dois utiliser ?
    quelle méthode ?
    merci de me donner une idée

  4. #4
    Membre chevronné
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    327
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Janvier 2009
    Messages : 327
    Par défaut
    Bonjour,
    Tiens voici le tuto sur les hook clavier souris en dotNet.
    http://humann.developpez.com/hook/
    A bientôt

  5. #5
    Membre éclairé Avatar de salihovic
    Inscrit en
    Février 2007
    Messages
    255
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 255
    Par défaut
    merci bien wakan
    c génial
    et aussi merci Louis-Guillaume Morand

  6. #6
    Membre éclairé Avatar de salihovic
    Inscrit en
    Février 2007
    Messages
    255
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 255
    Par défaut
    salut
    j'ai trouvé ce lien http://support.microsoft.com/kb/318804

    j'ai essayé de l'utilisé pour savoir avec un thread si l'utilisateur est actif ou pas

    le code de la classe est el suivant:
    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    public partial class Form1 : Form
    	{
    		public Form1()
    		{
    			InitializeComponent();
    		}
    		public static  bool mouseMoved = false;
    		public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
     
    		//Declare the hook handle as an int.
    		static int hHook = 0;
     
    		//Declare the mouse hook constant.
    		//For other hook types, you can obtain these values from Winuser.h in the Microsoft SDK.
    		public const int WH_MOUSE = 7;
     
     
    		//Declare MouseHookProcedure as a HookProc type.
    		HookProc MouseHookProcedure;
     
    		//Declare the wrapper managed POINT class.
    		[StructLayout(LayoutKind.Sequential)]
    		public class POINT
    		{
    			public int x;
    			public int y;
    		}
     
    		//Declare the wrapper managed MouseHookStruct class.
    		[StructLayout(LayoutKind.Sequential)]
    		public class MouseHookStruct
    		{
    			public POINT pt;
    			public int hwnd;
    			public int wHitTestCode;
    			public int dwExtraInfo;
    		}
     
    		//This is the Import for the SetWindowsHookEx function.
    		//Use this function to install a thread-specific hook.
    		[DllImport("user32.dll", CharSet = CharSet.Auto,
    		 CallingConvention = CallingConvention.StdCall)]
    		public static extern int SetWindowsHookEx(int idHook, HookProc lpfn,
    		IntPtr hInstance, int threadId);
     
    		//This is the Import for the UnhookWindowsHookEx function.
    		//Call this function to uninstall the hook.
    		[DllImport("user32.dll", CharSet = CharSet.Auto,
    		 CallingConvention = CallingConvention.StdCall)]
    		public static extern bool UnhookWindowsHookEx(int idHook);
     
    		//This is the Import for the CallNextHookEx function.
    		//Use this function to pass the hook information to the next hook procedure in chain.
    		[DllImport("user32.dll", CharSet = CharSet.Auto,
    		 CallingConvention = CallingConvention.StdCall)]
    		public static extern int CallNextHookEx(int idHook, int nCode,
    		IntPtr wParam, IntPtr lParam);
    		private void button2_Click(object sender, System.EventArgs e)
    		{
    			Thread ali = new Thread(new ThreadStart(go));
    	if(hHook == 0)
    	{
    	        // Create an instance of HookProc.
    		MouseHookProcedure = new HookProc(Form1.MouseHookProc);
     
    		hHook = SetWindowsHookEx(WH_MOUSE, 
    					MouseHookProcedure, 
    					(IntPtr)0,
    					AppDomain.GetCurrentThreadId());
     
    		ali.Start();
    		//If the SetWindowsHookEx function fails.
    		if(hHook == 0 )
    		{
    			MessageBox.Show("SetWindowsHookEx Failed");
    			return;
    		}
    		button2.Text = "UnHook Windows Hook";
    	}
    	else
    	{
    		bool ret = UnhookWindowsHookEx(hHook);
    		ali.Abort();
    		//If the UnhookWindowsHookEx function fails.
    		if(ret == false )
    		{
    			MessageBox.Show("UnhookWindowsHookEx Failed");
    			return;
    		}
    		hHook = 0;
    		button2.Text = "Set Windows Hook";
    		this.Text = "Mouse Hook";
    	} 
    }
    		public static int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
    		{
    			//Marshall the data from the callback.
    			MouseHookStruct MyMouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
     
    			if (nCode < 0)
    			{
    				mouseMoved = false;
    				return CallNextHookEx(hHook, nCode, wParam, lParam);
     
    			}
    			else
    			{
    				//Create a string variable that shows the current mouse coordinates.
    				String strCaption = "x = " +
    						MyMouseHookStruct.pt.x.ToString("d") +
    							"  y = " +
    				MyMouseHookStruct.pt.y.ToString("d");
    				//You must get the active form because it is a static function.
    				//Form tempForm = Form.ActiveForm;
     
    				//Set the caption of the form.
    				//tempForm.Text = strCaption;
    				//change the boolean value to true
    				mouseMoved = true;
    				return CallNextHookEx(hHook, nCode, wParam, lParam);
    			}
    		}
    		public  void go()
    		{
     
    			while (Thread.CurrentThread.IsAlive)
    			{
    				Thread.Sleep(10000);
    			if (!mouseMoved)
    			{
    				MessageBox.Show("c'est désactivé");
    			}
    			}
     
    		}
    	}
    le problème que sa marche pas
    c'est un problème de thread problablement
    sinon la méthode ou je recupère la valeur du mouvement est fausse
    merci de m'aider

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 13
    Dernier message: 19/02/2006, 16h54
  2. detecter si le cursor est au dessus d'un controle
    Par philippe V dans le forum MFC
    Réponses: 2
    Dernier message: 30/06/2005, 20h19
  3. Detecter si un Fichier est deja ouvert
    Par Didier Derain dans le forum C++Builder
    Réponses: 8
    Dernier message: 25/02/2005, 19h27
  4. Tester si un process est encore actif
    Par Damien2212 dans le forum Windows
    Réponses: 2
    Dernier message: 17/09/2004, 15h33
  5. Detection si une BD est sollicitée
    Par Yepazix dans le forum Bases de données
    Réponses: 6
    Dernier message: 31/08/2004, 19h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo