473,394 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Detect mouse movement from minimized application

Hi there,

I'm new to VB2005 so its probably a very simple answer too! But i just
can't think how to do it...

Basically i need to detect mouse (and preferably keyboard) movement and
kepresses when my application is just minimized and not the active
forground app.

I only need to triger an event which is going to tell my app if the
user has moved the mouse recently and decide if the workstation is now
idle, nothing more - so any ideas?

cheers in advance!

- - rob - -

Sep 20 '06 #1
3 4934

squeak ha scritto:
Hi there,

I'm new to VB2005 so its probably a very simple answer too! But i just
can't think how to do it...

Basically i need to detect mouse (and preferably keyboard) movement and
kepresses when my application is just minimized and not the active
forground app.

I only need to triger an event which is going to tell my app if the
user has moved the mouse recently and decide if the workstation is now
idle, nothing more - so any ideas?

cheers in advance!

- - rob - -
hi rob, you got to attach a hook routine to the keyboard or mouse
messages:

create a public class with two public sub, startListen and stopListen,
and a public event, KeyPressed returning key's been pressed.

here's the keyboard procedure:

Public Function MyLLKbdProc(ByVal nCode As Integer, ByVal wParam As
IntPtr, ByVal lParam As IntPtr) As IntPtr
RaiseEvent KeyPressed(Marshal.ReadInt32(lParam))
Return CallNextHookEx(KeyBoardHook, nCode, wParam, lParam)
End Function

and this is the calling routine;

Public Sub KeyBoardListen()
Dim hp1 As HookProc = AddressOf MyLLKbdProc
KeyBoardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
hp1, Marshal.GetHINSTANCE(GetType(Hook).Module), 0)
GC.KeepAlive(hp1)
End Sub

hope this help, fabio

Sep 20 '06 #2
hi fabio!

thankyou very much for your rapid reply!

now i'm sure for most people this would be all they need to get things
going - but i'm afraid i'm not quite up to that level yet and am still
slightly stuck even with what you have given me!

sorry to be a pain but could you be a bit more detailed with the class
i need to create? from what you have said i assume i need something
like:

Public Class KeyboardListen

Public Sub startListen()

End Sub

Public Sub stopListen()

End Sub

Public Event KeyPressed()

End Class

could you give me some more detail on where i put the other code
samples you gave me and how to use it?

once again sorry for being stupid, but i'm still very new to this!

thanks again!!
- - rob - -

Sep 20 '06 #3
no problem, let's be more detailed :-D

Public Class Hook

' DECLARATION

Public Event KeyPressed(ByVal KeyChar As Int32)

Delegate Function HookProc(ByVal nCode As Integer, ByVal wParam As
IntPtr, _
ByVal lParam As IntPtr) As IntPtr

Declare Auto Function SetWindowsHookEx Lib "user32.dll" (ByVal
idHook As Integer, ByVal lpfn As HookProc, ByVal hMod As IntPtr, ByVal
dwThreadId As Integer) As IntPtr

Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hhk As
IntPtr)
As Boolean

Declare Function CallNextHookEx Lib "user32.dll" (ByVal hhk As
IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As
IntPtr) As IntPtr

Const WH_KEYBOARD_LL As Integer = 13
Shared KeyBoardHook As IntPtr

Public Function MyLLKbdProc(ByVal nCode As Integer, ByVal wParam As
IntPtr, ByVal lParam As IntPtr) As IntPtr
RaiseEvent KeyPressed(Marshal.ReadInt32(lParam))
Return CallNextHookEx(KeyBoardHook, nCode, wParam, lParam)
End Function

Public Sub KeyBoardListen()
Dim hp1 As HookProc = AddressOf MyLLKbdProc
KeyBoardHook = SetWindowsHookEx(WH_KEYBOARD_LL, hp1,
Marshal.GetHINSTANCE(GetType(Hook).Module), 0)
GC.KeepAlive(hp1)
End Sub

Public Sub KeyBoardStopListen()
UnhookWindowsHookEx(KeyBoardHook)
End Sub

End Class

enjoy ;-)

Sep 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: BadOmen | last post by:
I want my program to send a mouse click to the window at the current mouse position, how do I do that? Example: I have my mouse over a button in Word and then my program is sending the left...
19
by: Frank Rizzo | last post by:
I want to log the user out when there has been a period of inactivity in the application. The key here is inactivity of the application, not the system. I know that you can retrieve the...
6
by: Carlos García-Carazo | last post by:
Hello, I am working on a C# application for an industrial machine, using Windows Forms, where the user could look at the screen from a 90 degree rotated position, like he could turn the monitor...
1
by: Benny Raymond | last post by:
In my attempt to make a macro recording program where i can then playback mouse movements i'm running into a big problem: I'm trying to simulate the movement of the mouse to a point on the...
3
by: garyusenet | last post by:
I have a programme written in C++, the programme is unmanaged and is an executable, i don't have any source code. I'm writing a C# program. I want to (a) start the programme minimized. (b) send...
4
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be programmed. Stop snickering!!! I didn't do it...I...
5
by: hurricane_number_one | last post by:
I am creating a simple server application, that will listen for incoming mouse coordinates and then move the mouse accordingly. So basically it's like a very simple VNC server without and screen...
6
by: c.k. | last post by:
I was wondering if there was a way to give mouse movement on an empty form some lag/delay? For instance, user moves mouse, and the cursor is 20ms (possible adjustable from some option) behind the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.