473,779 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4965

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(ByV al nCode As Integer, ByVal wParam As
IntPtr, ByVal lParam As IntPtr) As IntPtr
RaiseEvent KeyPressed(Mars hal.ReadInt32(l Param))
Return CallNextHookEx( KeyBoardHook, nCode, wParam, lParam)
End Function

and this is the calling routine;

Public Sub KeyBoardListen( )
Dim hp1 As HookProc = AddressOf MyLLKbdProc
KeyBoardHook = SetWindowsHookE x(WH_KEYBOARD_L L,
hp1, Marshal.GetHINS TANCE(GetType(H ook).Module), 0)
GC.KeepAlive(hp 1)
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(ByVa l KeyChar As Int32)

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

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

Declare Function UnhookWindowsHo okEx 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(ByV al nCode As Integer, ByVal wParam As
IntPtr, ByVal lParam As IntPtr) As IntPtr
RaiseEvent KeyPressed(Mars hal.ReadInt32(l Param))
Return CallNextHookEx( KeyBoardHook, nCode, wParam, lParam)
End Function

Public Sub KeyBoardListen( )
Dim hp1 As HookProc = AddressOf MyLLKbdProc
KeyBoardHook = SetWindowsHookE x(WH_KEYBOARD_L L, hp1,
Marshal.GetHINS TANCE(GetType(H ook).Module), 0)
GC.KeepAlive(hp 1)
End Sub

Public Sub KeyBoardStopLis ten()
UnhookWindowsHo okEx(KeyBoardHo ok)
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
32655
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 mouse click and the button under the mouse is clicked. Yours, Jonas
19
46685
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 inactivity of the system via GetLastInputInfo. That's not what I want - I want inactivity of the application. Thanks.
6
10816
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 to leave it standing on its left (or right) side. There are many ways to show a "turned" interface in this case, but the problem is that when he moves the mouse right, in a turned screen the mouse cursor goes down (or up), when he moves it up...
1
19228
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 screen. With my current code the mouse is only moving in the X direction and not in the Y direction (however my debug line is telling me that it's trying to move in the Y as well). I've read everything I could find online, tried some hacky ways of...
3
3613
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 keystrokes to the programme, and mouse strokes. Can you please tell me how I would do this assuming the programme is called "c:\programme.exe"
4
6977
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 just gotta fix it. I need to make some calculations on the measurements and VB6 is my language. Yes, the system mouse will corrupt the measurement, but it's an auditing function and that's acceptable.
5
2331
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 display. I have this basic part working. The problem is that response time is really bad. It seems like the server is not receiving the data fast enough to be able to move the mouse so that it appears to be in sync with the movement on the client...
6
3117
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 movement. So when user stops moving mouse, 20ms later the cursor itself stops moving... I tried using: Windows.Forms.Cursor.Current.Position = New System.Drawing.Point(x,y) and forms of sleep/timer events but cant seem to get it to work...
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9930
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.