Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18011
Number of posts: 55384

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
ShiftKey command Posted by WDMaples on 29 Jul 2005 at 12:40 PM
Can anyone give me and/or syntax for the ShiftKey command? I was trying to write a script in Dragon NaturallySpeaking that uses Visual Basic and I need a script that will hold down the shift key while pressing the left mouse button. I have been getting a syntax error on the ShiftKey 1, 1.

Thanks,
Doug
Report
Re: ShiftKey command Posted by superjoe30 on 29 Jul 2005 at 2:00 PM
: Can anyone give me and/or syntax for the ShiftKey command? I was trying to write a script in Dragon NaturallySpeaking that uses Visual Basic and I need a script that will hold down the shift key while pressing the left mouse button. I have been getting a syntax error on the ShiftKey 1, 1.
:
: Thanks,
: Doug
:

Do you want the script to control the mouse and keyboard, or do you want the script to handle mouse and keyboard events?

If the latter, use this:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Shift = 1 Then
  msgbox "Shift is down"
else
  msgbox "Shift is up"
end if

End Sub





_____ __________ _____
_____-SUPERJOE30-_____
__-Superjoe Software-__


Report
Re: ShiftKey command Posted by WDMaples on 29 Jul 2005 at 2:27 PM
: : Can anyone give me and/or syntax for the ShiftKey command? I was trying to write a script in Dragon NaturallySpeaking that uses Visual Basic and I need a script that will hold down the shift key while pressing the left mouse button. I have been getting a syntax error on the ShiftKey 1, 1.
: :
: : Thanks,
: : Doug
: :
:
: Do you want the script to control the mouse and keyboard, or do you want the script to handle mouse and keyboard events?
:
: If the latter, use this:
:
: 
: Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
: 
: If Shift = 1 Then
:   msgbox "Shift is down"
: else
:   msgbox "Shift is up"
: end if
: 
: End Sub
: 
I want it to control the mouse and keyboard.  I'm a quadriplegic and I use Dragon NaturallySpeaking exclusively to run my computer.  When I am in Internet Explorer, I cannot go to a link and press the shift key and click the mouse to open the link in new window.  The advanced scripting uses "most" Visual Basic commands.  Someone had given the following lines to accomplish it, but I get a syntax error on the ShiftKey 1, 1 line.

ShiftKey 1, 1
ButtonClick 1, 1
ShiftKey 0, 1

Thanks,
Doug

Report
Re: ShiftKey command Posted by superjoe30 on 1 Aug 2005 at 8:27 AM
: : : Can anyone give me and/or syntax for the ShiftKey command? I was trying to write a script in Dragon NaturallySpeaking that uses Visual Basic and I need a script that will hold down the shift key while pressing the left mouse button. I have been getting a syntax error on the ShiftKey 1, 1.
: : :
: : : Thanks,
: : : Doug
: : :
: :
: : Do you want the script to control the mouse and keyboard, or do you want the script to handle mouse and keyboard events?
: :
: : If the latter, use this:
: :
: : 
: : Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
: : 
: : If Shift = 1 Then
: :   msgbox "Shift is down"
: : else
: :   msgbox "Shift is up"
: : end if
: : 
: : End Sub

: :
: I want it to control the mouse and keyboard. I'm a quadriplegic and I use Dragon NaturallySpeaking exclusively to run my computer. When I am in Internet Explorer, I cannot go to a link and press the shift key and click the mouse to open the link in new window. The advanced scripting uses "most" Visual Basic commands. Someone had given the following lines to accomplish it, but I get a syntax error on the ShiftKey 1, 1 line.
:
: ShiftKey 1, 1
: ButtonClick 1, 1
: ShiftKey 0, 1
:
: Thanks,
: Doug
:
:

Here are some windows API that you can use to control the mouse and the keyboard:


'key board
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetKeyState Lib "user32" (ByVal vVirtKey As Long) As Integer


'mouse
Private Type PointAPI
    X As Long
    Y As Long
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_ABSOLUTE = &H8000 '  absolute move
Private Const MOUSEEVENTF_LEFTDOWN = &H2 '  left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 '  left button up
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20 '  middle button down
Private Const MOUSEEVENTF_MIDDLEUP = &H40 '  middle button up
Private Const MOUSEEVENTF_MOVE = &H1 '  mouse move
Private Const MOUSEEVENTF_RIGHTDOWN = &H8 '  right button down
Private Const MOUSEEVENTF_RIGHTUP = &H10 '  right button up


So if you want to check the mouse position, use:
Dim Pt As PointAPI

GetCursorPos Pt

'pt.x and pt.y are the coordinates


To see if a key is down, use:
Dim Ret As Long
dim Key as Integer

key = vbkeyspace '<- that's the key you want to check
Ret = Abs(GetKeyState(CLng(Key)))
            If Ret > 1  Then
                'key is down
            ElseIf Ret <= 1  Then
                'key is up
            End If


To trigger a key, use:

keybd_event Key, 0, 0, 0


To trigger a mouse movement, use:

SetCursorPos X, Y


To trigger a mouse click, use:

mouse_event MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0



_____ __________ _____
_____-SUPERJOE30-_____
__-Superjoe Software-__





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.