473,395 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Holding down a key

Is there a way to hold down keys in vb.net?

In the program I am writing I can simulate a MOUSE button hold down:

Public 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)

Public Const MOUSEEVENTF_LEFTDOWN As Object = &H2

Public Const MOUSEEVENTF_LEFTUP As Object = &H4

Public Sub LeftDown()

mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)

End Sub

Public Sub LeftUp()

mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

End Sub

Public Sub LeftClick()

LeftDown()

LeftUp()

End Sub

So I am Sure I can do this with a keyboard key (Specifically ALT, and the
SHIFT keys). Sendkeys does not work (Its much like a click by sending a down
AND an UP). As you can see I googled and found that using the hex &H2 to
simulate a mouse button click worked I am sure there is a way to do it for
the keyboard. Thanks if you can provide help.
Jul 17 '06 #1
2 4150
Daniel,

I don't see much VBNet code in what you show, it is more using VBNet to code
Win32

However usualy is doing this just done by setting a keydown switch which is
togled.

Here a sample with some dynamic controls that you can mode over your screen
completely with VBNet code..

http://www.vb-tips.com/dbPages.aspx?...1-47ef665ea0c2

I hope this helps,

Cor

"Daniel N" <sa***********@yahoo.comschreef in bericht
news:aX****************@fe08.lga...
Is there a way to hold down keys in vb.net?

In the program I am writing I can simulate a MOUSE button hold down:

Public 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)

Public Const MOUSEEVENTF_LEFTDOWN As Object = &H2

Public Const MOUSEEVENTF_LEFTUP As Object = &H4

Public Sub LeftDown()

mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)

End Sub

Public Sub LeftUp()

mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

End Sub

Public Sub LeftClick()

LeftDown()

LeftUp()

End Sub

So I am Sure I can do this with a keyboard key (Specifically ALT, and the
SHIFT keys). Sendkeys does not work (Its much like a click by sending a
down AND an UP). As you can see I googled and found that using the hex &H2
to simulate a mouse button click worked I am sure there is a way to do it
for the keyboard. Thanks if you can provide help.


Jul 17 '06 #2
"Daniel N" <sa***********@yahoo.comschrieb:
Public 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)

Public Const MOUSEEVENTF_LEFTDOWN As Object = &H2

Public Const MOUSEEVENTF_LEFTUP As Object = &H4
=>

\\\
Public Declare Sub mouse_event Lib "user32.dll" ( _
ByVal dwFlags As Int32, _
ByVal dx As Int32, _
ByVal dy As Int32, _
ByVal cButtons As Int32, _
ByVal dwExtraInfo As Int32 _
)

Public Const MOUSEEVENTF_LEFTDOWN As Int32 = &H2
Public Const MOUSEEVENTF_LEFTUP As Int32 = &H4
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jul 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: listerofsmeg | last post by:
Hi all, Fairly new to the world of .NET, but since installing it, IE has been playing up. When I installed, I'm sure I remember some dialog saying something like "Do you want .Net to improve...
5
by: Alex Stevens | last post by:
Hi All, I'm writing a launcher program which checks for updates and copies them down to the client. However, I would like the user to be able to modify the settings for the launcher. As this...
3
by: Novice Computer User | last post by:
I have a drop down menu where people are able to select 1 item. However, I want to modify the drop down list so that the person can select more than 1 item (i.e by holding down the shift button...
5
by: Daniel N. | last post by:
I am trying have an application hold down the Shift key (+) and the Alt key (%) simultaneously for a given period of time, or until a condition is met. I tried this but it doesn't work:...
3
by: Daniel N | last post by:
In my never ending search I found code that might help me to simulate holding down keys: http://www.developerfusion.co.uk/show/68/2/ However, when I copy and paste, I get the errors;
6
by: Eric Layman | last post by:
Is there a way to detect a held-down button while the mouse is moving? Thanks. Posted Via Usenet.com Premium Usenet Newsgroup Services
0
by: kronus | last post by:
Hi everyone, Yes, I need to use you guys as a sounding board once more :-) I have a button that has two listeners one for mouse up and the other for mouse down and they point to the same...
6
by: Palehorse | last post by:
I'd like to apologize upfront for me saying "I'm not a programer", I'm sure you all hear this a hundred times a day. Unfortunately, in this case, it's true. I've been working on trying to figure out...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.