Program running on background

Page 1 of 1

2 Replies - 310 Views - Last Post: 18 January 2013 - 10:32 AM Rate Topic: -----

#1 Vija02  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-January 13

Program running on background

Posted 17 January 2013 - 09:31 PM

Hello, i am making a program to allow moving cursor using keyboard
however, it only allows the user to move the cursor when its on the program interface. Is there any way for the program to run in the background so that the user can use it on desktop?

Code i use:
 
Private Sub KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyValue = Keys.Left Then
            Me.Cursor = New Cursor(Cursor.Current.Handle)
            Cursor.Position = New Point(Cursor.Position.X - 1, Cursor.Position.Y - 0)
            Cursor.Clip = New Rectangle(Me.Location, Me.Size)
        End If
        If e.KeyValue = Keys.Right Then
            Me.Cursor = New Cursor(Cursor.Current.Handle)
            Cursor.Position = New Point(Cursor.Position.X + 1, Cursor.Position.Y - 0)
            Cursor.Clip = New Rectangle(Me.Location, Me.Size)
        End If
        If e.KeyValue = Keys.Up Then
            Me.Cursor = New Cursor(Cursor.Current.Handle)
            Cursor.Position = New Point(Cursor.Position.X - 0, Cursor.Position.Y - 1)
            Cursor.Clip = New Rectangle(Me.Location, Me.Size)
        End If
        If e.KeyValue = Keys.Down Then
            Me.Cursor = New Cursor(Cursor.Current.Handle)
            Cursor.Position = New Point(Cursor.Position.X - 0, Cursor.Position.Y + 1)
            Cursor.Clip = New Rectangle(Me.Location, Me.Size)
        End If
    End Sub


and for the KeyUp
    Private Sub KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
        If e.KeyValue = Keys.Left Then
            Me.Cursor = New Cursor(Cursor.Current.Handle)
            Cursor.Position = New Point(Cursor.Position.X - 0, Cursor.Position.Y - 0)
            Cursor.Clip = New Rectangle(Me.Location, Me.Size)
        End If
        If e.KeyValue = Keys.Right Then
            Me.Cursor = New Cursor(Cursor.Current.Handle)
            Cursor.Position = New Point(Cursor.Position.X + 0, Cursor.Position.Y - 0)
            Cursor.Clip = New Rectangle(Me.Location, Me.Size)
        End If
        If e.KeyValue = Keys.Up Then
            Me.Cursor = New Cursor(Cursor.Current.Handle)
            Cursor.Position = New Point(Cursor.Position.X + 0, Cursor.Position.Y - 0)
            Cursor.Clip = New Rectangle(Me.Location, Me.Size)
        End If
        If e.KeyValue = Keys.Down Then
            Me.Cursor = New Cursor(Cursor.Current.Handle)
            Cursor.Position = New Point(Cursor.Position.X - 0, Cursor.Position.Y - 0)
            Cursor.Clip = New Rectangle(Me.Location, Me.Size)
        End If
    End Sub


My second question is: is it possible not to have the KeyUp code?
Any help is appreciated
Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Program running on background

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,662
  • Joined: 02-June 10

Re: Program running on background

Posted 18 January 2013 - 09:20 AM

You already have issues with trying to use this system wide.
Cursor.Position for example is relative to the form. You would need to have started this with the intention of it being at a deeper OS level and calculate to the screen position and geometry, not the form.

There are ways of doing system wide keyboard hooks - but that gets into the area of code that can be misused to create keyloggers and we won't help with projects that have that kind of potential for malice.
Was This Post Helpful? 0
  • +
  • -

#3 Vija02  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-January 13

Re: Program running on background

Posted 18 January 2013 - 10:32 AM

Well, thanks for the reply tlhln'tog
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1