Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Visual Basic Idle Time


  • Please log in to reply

#1
BirdieUK

BirdieUK

    Member

  • Member
  • PipPip
  • 33 posts
Hey, i'm using Visual Basic Express 2005 and i'd like to be able to run a function if the system is idle for a certain amount of time. So i'm basically asking if anyone knows how to track idle time of both keyboard and mouse using VB?

Thanks, keep in note of the version i am using...
  • 0

Advertisements


#2
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
Well, assuming you have some basic knowledge of the language you are using (:whistling:), here's what you could do:

1. Have a timer object and have the interval length set at whatever amount of time you want to be the point where you consider the computer to be idle. (ie. 5 mins... though it must be done in milliseconds... so that would be 30000 i believe)

2. At the timer's tick event, have the program do whatever you want it to do when the computer is idle.

3. But, (this is where we check for if the computer is actually idle) also have KeyPress and MouseMove (and maybe MouseClick... I mean it is possible for someone to click without moving their mouse...) events, and if either of them occur, stop the timer, then start it again.

If you need more explaining or maybe an example (of code), feel free to ask. Hopefully this is a good starting point for you to do what you want. :blink:

Edited by stettybet0, 21 July 2007 - 10:17 AM.

  • 0

#3
BirdieUK

BirdieUK

    Member

  • Topic Starter
  • Member
  • PipPip
  • 33 posts
Ok thanks, thats a better logical method of what i was thinking with the timer object.

Er, however, ive been experiencing problems on finding a method to detect whether a mouse has been moved in express 2005...

Also, is there is another method for detecting key presses besides looping through every key available to check their state? If not, its ok, just saves time really...

Thanks for replying. Oh and i do have basic knowledge of VB.

PS. The other main problem is that this program will be a background process (no its nothing like a keylogger, it just times your idle time for a website)

EDIT: More onto this lil subject.. :whistling:, er i'd need to have 2 timers right? 1 like you said and 1 that keeps checking movement because by what your saying, wouldnt the detection only be every 5 minutes?

Edited by BirdieUK, 21 July 2007 - 10:32 AM.

  • 0

#4
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts

Er, however, ive been experiencing problems on finding a method to detect whether a mouse has been moved in express 2005...


Under your form events, the MouseMove event should detect if the mouse has been moved.

Also, is there is another method for detecting key presses besides looping through every key available to check their state? If not, its ok, just saves time really...


Again, under form event, the KeyPress event should detect if any key has been pressed.

So here's an example: (The form is called "Idle", and the timer is called "Timer".)

Public Class Idle

	Private Sub Idle_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		'You should have already set the interval in the designer... 
		Timer.Start()
	End Sub

	Private Sub Idle_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
		Timer.Stop()
		Timer.Start()
	End Sub

	Private Sub Idle_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
		Timer.Stop()
		Timer.Start()
	End Sub

	Private Sub Idle_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
		Timer.Stop()
		Timer.Start()
	End Sub

	Private Sub Timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer.Tick
		Application.Exit() 'I just have the program exiting, though you could have it do whatever you want.
	End Sub
End Class

Edit: Oh, and 5 mins would equal 300000 milliseconds, not 30000. :whistling:

Edited by stettybet0, 21 July 2007 - 10:40 AM.

  • 0

#5
BirdieUK

BirdieUK

    Member

  • Topic Starter
  • Member
  • PipPip
  • 33 posts
wow! Thanks alot.

Feels weird getting helped on something like this by a guy my age :\ :whistling:

1 quick question though, the events such as keypress,etc. only work when its focused on the form? Is there a way past this? Sorry if this sounds like your spoonfeeding me all of this, i hate being in this situation lol.

Edited by BirdieUK, 21 July 2007 - 10:53 AM.

  • 0

#6
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
Haha, I understand. People our age usually aren't very knowledgeable with this kinda stuff... :whistling:

Well, glad I could help.

Edit: saw your edit... alright... that is a bit of a problem... I don't have much experience with making programs which run in the background, and I'm not sure how we could get it to capture input on anything (other than itself). I think it might involve an API call to detect the actual input of the keyboard and mouse to the computer, but I'm not sure how to do that off the top of my head... I'll try to get back to you after I've done a little research.

Edited by stettybet0, 21 July 2007 - 10:58 AM.

  • 0

#7
BirdieUK

BirdieUK

    Member

  • Topic Starter
  • Member
  • PipPip
  • 33 posts
Ok thanks alot.

I'll try some other forums also to see if anyone can bring some light into this. I'll keep an eye on this in case you find something :whistling:
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP