LetchfordP
asked on
Visual Basic 2010 How can I tell if the user stops pressing a key
Hi all
I am using the code below and I just need a way of telling if the user has stopped pressing a key.
Have tried to use Key up but I can not get it to work? please can you show me how I can do it Thanks
I am using the code below and I just need a way of telling if the user has stopped pressing a key.
Have tried to use Key up but I can not get it to work? please can you show me how I can do it Thanks
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
Select keyData
Case Keys.Down
key1 = Keys.Down
If key2 <> key1 Then
Call tiltdown1()
End If
key2 = key1
Case Keys.Up
key1 = Keys.Up
If key2 <> key1 Then
Call tiltup1()
End If
key2 = key1
Case Keys.Right
key1 = Keys.Right
If key2 <> key1 Then
Call Panright1()
End If
key2 = key1
Case Keys.Left
key1 = Keys.Left
If key2 <> key1 Then
Call Panleft1()
End If
key2 = key1
Case Keys.M
key1 = Keys.M
If key2 <> key1 Then
Call zoomout1()
End If
key2 = key1
Case Keys.N
key1 = Keys.N
If key2 <> key1 Then
Call zoomin1()
End If
key2 = key1
Case Keys.S
key1 = Keys.S
If key2 <> key1 Then
Call allstop1()
End If
key2 = key1
End Select
Return temp(0)
End Function
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did try this as a test it still did not work
what am i doing wrong?
Public Class Form1
Dim keycon
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Private Sub Form_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
Select Case KeyCode
Case Keys.Up
keycon = 1
Call printb()
Case Keys.Down
keycon = 2
Call printb()
Case Keys.Right
keycon = 3
Call printb()
Case Keys.Left
keycon = 4
Call printb()
Case Else
End Select
End Sub
Private Sub printb()
TextBox1 = keycon
End Sub
End Class
what am i doing wrong?
Public Class Form1
Dim keycon
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Private Sub Form_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
Select Case KeyCode
Case Keys.Up
keycon = 1
Call printb()
Case Keys.Down
keycon = 2
Call printb()
Case Keys.Right
keycon = 3
Call printb()
Case Keys.Left
keycon = 4
Call printb()
Case Else
End Select
End Sub
Private Sub printb()
TextBox1 = keycon
End Sub
End Class
@LetchfordP
I don't see that you've coded a KeyUp() event, just a KeyDown() event.
I don't see that you've coded a KeyUp() event, just a KeyDown() event.
ASKER
That is true but if I can get key down to work so will key up
can someone show me what I am doing wrong
can someone show me what I am doing wrong
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question is about detecting the un-pressing of a key. That is done with the KeyUp() event.
ASKER
Jacques Bourgeois (James Burger)
Thank you for your help that is what I need someone to explain it in simple terms
aikimark
I did not know how to get the key"anything" to work
Thank you to all for your help
Thank you for your help that is what I need someone to explain it in simple terms
aikimark
I did not know how to get the key"anything" to work
Thank you to all for your help
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Chris
Yes I did but I did not work and I do not know how to make it work
Sorry very new to this
Yes I did but I did not work and I do not know how to make it work
Sorry very new to this
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Chris
If you have the time yes please
I can then see how you can make it work
I can now find the keyPreview property
but as for setting up a timer help please
Paul
If you have the time yes please
I can then see how you can make it work
I can now find the keyPreview property
but as for setting up a timer help please
Paul
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Guys
Well where to start I have worked with computers most of my life (59) but never done any VB programming or any thing other than a bit of code for the Sinclair spectrum z80.
Why do i need this program. well I help out in our local church and we have a 3 video PTZ cameras to stream the program out to the web so ones that are ill or far away can still see the program. We use a program called Vmix to do all the mixing and sending but the PTZ's came with a joystick and a switch box. We had a guy help out by doing a program and for a time it worked well but he moved away and we need to change the PTZ cameras we now have 3 cameras to control and do not want to us the old joystick so I said and you can guess the rest. so now have 1 of the cams home so I can test it out and thought I will use VB as it was free!!! So now I can with the help of you 2 can get the camera to track and remember where people are I have a big Form with a photo of all the congregation so all you have to do is click on the photo and the camera will goto that person all I need to do next is add the part to send the camera to the Vmix program it is built to receive commands on port 8080 this a bit of the code to send out the cut command to switch cameras (good old google):
Private Sub Cut1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cut1.Click
'Public Shared Sub Main()
' Create a request for the URL.
Dim request As WebRequest = _
WebRequest.Create("http://127.0.0.1:8088/api/?Function=cut")
' If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCre dentials
' Get the response.
Dim response As WebResponse = request.GetResponse()
' Display the status.
Console.WriteLine(CType(re sponse, HttpWebResponse).StatusDes cription)
' Get the stream containing content returned by the server.
Dim dataStream As Stream = response.GetResponseStream ()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
Console.WriteLine(response FromServer )
' Clean up the streams and the response.
reader.Close()
response.Close()
End Sub
and to make it work all the time, sort out so when you click on a photo 1st time we send a command to the cam to move, wait until it gets there, and them send the cut command to vmix to display the camera, when you click photo the 2nd time you send a cut command again to switch cameras but to the platform display. and so more work trying to find people take there photo and put it in the box so the next time they answer you just click on them again to save time tracking the camera. and then ?
and next time do not volunteer!!!
PS I do not know how the program works but but I will get there, only spent about 4 nights so far thanks you guys and Google. you are right to say get a book and take some youtube but I am so short on time.
Anyway how do I give you guys some points?
Well where to start I have worked with computers most of my life (59) but never done any VB programming or any thing other than a bit of code for the Sinclair spectrum z80.
Why do i need this program. well I help out in our local church and we have a 3 video PTZ cameras to stream the program out to the web so ones that are ill or far away can still see the program. We use a program called Vmix to do all the mixing and sending but the PTZ's came with a joystick and a switch box. We had a guy help out by doing a program and for a time it worked well but he moved away and we need to change the PTZ cameras we now have 3 cameras to control and do not want to us the old joystick so I said and you can guess the rest. so now have 1 of the cams home so I can test it out and thought I will use VB as it was free!!! So now I can with the help of you 2 can get the camera to track and remember where people are I have a big Form with a photo of all the congregation so all you have to do is click on the photo and the camera will goto that person all I need to do next is add the part to send the camera to the Vmix program it is built to receive commands on port 8080 this a bit of the code to send out the cut command to switch cameras (good old google):
Private Sub Cut1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cut1.Click
'Public Shared Sub Main()
' Create a request for the URL.
Dim request As WebRequest = _
WebRequest.Create("http://127.0.0.1:8088/api/?Function=cut")
' If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCre
' Get the response.
Dim response As WebResponse = request.GetResponse()
' Display the status.
Console.WriteLine(CType(re
' Get the stream containing content returned by the server.
Dim dataStream As Stream = response.GetResponseStream
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
Console.WriteLine(response
' Clean up the streams and the response.
reader.Close()
response.Close()
End Sub
and to make it work all the time, sort out so when you click on a photo 1st time we send a command to the cam to move, wait until it gets there, and them send the cut command to vmix to display the camera, when you click photo the 2nd time you send a cut command again to switch cameras but to the platform display. and so more work trying to find people take there photo and put it in the box so the next time they answer you just click on them again to save time tracking the camera. and then ?
and next time do not volunteer!!!
PS I do not know how the program works but but I will get there, only spent about 4 nights so far thanks you guys and Google. you are right to say get a book and take some youtube but I am so short on time.
Anyway how do I give you guys some points?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well guys you certainly know how to cheer somebody up, of course you are right and if I could think of a use for it out side of this project it would make sense to do as you say sit down and at least learn the elementary stuff. But someone has got to help them as the deaf do not get much help from the state, and we cannot hire someone to do it.
You are right I do not know my left from my right but I'm getting there spent another couple of hours last night and now my program talks to their program and I can cut and select from any one of the three cameras and umpteen power points, films whatever needs to be displayed. Very long way to go, and you would not approve, but needs must.
I do need to know why using keydown I can see all the keys except the arrow keys (not the arrow keys on the keypad can see them)
but I better ask some where else
Ok I will end here and stop bothering yourselves.
Thanks for your time
You are right I do not know my left from my right but I'm getting there spent another couple of hours last night and now my program talks to their program and I can cut and select from any one of the three cameras and umpteen power points, films whatever needs to be displayed. Very long way to go, and you would not approve, but needs must.
I do need to know why using keydown I can see all the keys except the arrow keys (not the arrow keys on the keypad can see them)
but I better ask some where else
Ok I will end here and stop bothering yourselves.
Thanks for your time
ASKER
Thank you again for you time
ASKER
Ok I give points to one of you but how do i give to 2nd person?
ASKER
Thanks for your time and your effort, I will get there in the end
Have a grand day
Have a grand day
ASKER
I only have 1 form called Form1, how do I make the KeyPreview property to True part of the form
tired Form1 = KeyPreview = True at the start of the program comes up with error Form1
tired to put it in the Sub but still the same error.
just need to do the arrow keys could you give me a working bit of VB i can try please
must be missing the point somewhere.
thank you both for your reply's