Solved

pressing shift key in vb.net

Posted on 2009-05-19
6
446 Views
Last Modified: 2012-05-07
i want to create an app that automatically send out a shift key like someone just press it on the keyboard. can you help? thanks.
0
Comment
Question by:StewSupport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
CyberLex earned 500 total points
ID: 24422194
depends on what you want to achieve I guess. for example SendKeys.Send(Keys.Shift)
sends shift to the active application.

cheers
Lex
0
 

Author Comment

by:StewSupport
ID: 24422879
just to stop screen saver form starting. so it really trying to fake the machine that the computer is not inactive.
i have a loop that every 30 second send the key escape and screen saver kicks in if computer is inactive for 1 minute. the escape key is still being hit by the app but screen saver still kick in  until the next esc hit within the next 30 sec it returns to normal screen. why doesn't screen saver just stay off when the esc key is hit?
0
 

Author Comment

by:StewSupport
ID: 24422895
just to stop screen saver form starting. so it really trying to fake the machine that the computer is not inactive.
i have a loop that every 30 second send the key escape. i set screen saver kicks in if computer is inactive for 1 minute. the escape key is still being hit by the app every 30 seconds but screen saver still kick in  until the next esc is hit from the app. why doesn't screen saver just stay off when the esc key is hit?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24423179
This worked fine for me...successfully preventing the screensaver from invoking.  All it does is move the mouse by one pixel in the x and y directions every 59 seconds and then puts it back.  I didn't even notice it moving.  Running VB.Net 2008 on a 64 bit Vista Home Premium system:
Public Class Form1
 
    Private WithEvents tmr As New Timer
 
    Private Const MOUSEEVENTF_MOVE As Integer = &H1
    Private Declare Sub mouse_event Lib "user32" _
        (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, _
        ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        tmr.Interval = TimeSpan.FromSeconds(59).TotalMilliseconds
        tmr.Enabled = True
    End Sub
 
    Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
        mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0) ' move the mouse slightly
        mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0) ' put it back
    End Sub
 
End Class

Open in new window

0
 

Author Comment

by:StewSupport
ID: 24423257
i had something like that but i guess microsoft detects that the mouse movement was not sent from  hardware but software so my code didnt do anything. here is what i had before
Imports System.Windows.Forms
Public Class MouseMover
    Inherits System.Windows.Forms.Form
    <Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function SetCursorPos(ByVal X As Integer, ByVal Y As Integer) As Boolean
    End Function
 
    Private Sub MouseMover_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
        Timer1.Enabled = True
        Timer1.Interval = 30000
        Me.Visible = False
        Me.ShowInTaskbar = False
        Me.NotifyIcon1.Icon = Me.Icon
        Me.NotifyIcon1.Visible = True
    End Sub
 
    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim random As New Random
        Dim x As Integer = random.Next
        Dim y As Integer = random.Next
        SetCursorPos(x, y)
    end sub
end class

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24423290
We'll...give my code a whirl!  I used mouse_event() instead of SetCursorPos().  Additionally, I'm simply moving the cursor by ONE pixel to the Right and Down and then putting it RIGHT BACK.  It worked on my system (Vista)...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question