|
-
Jun 30th, 2005, 02:59 PM
#1
Thread Starter
Lively Member
hotkeys (un-fixed)(re-fixed*self solved*)
this is my first post. weee!!
i am trying to make hotkeys for an event of a program i am making.
i have this so far but it wont work.
VB Code:
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If System.Windows.Forms.Keys.F7 Then
My.Computer.Keyboard.SendKeys(TextBox1.Text)
My.Computer.Keyboard.SendKeys("{enter)")
End If
End Sub
End Class
i understand why it wont work, but i cant figure out what to write to make it work.
i think it is the "If System.Windows.Forms.Keys.F7 Then" part.
could someone help me?
Last edited by ader10; Jul 4th, 2005 at 03:15 PM.
-
Jun 30th, 2005, 03:16 PM
#2
Re: hotkeys
Put the code in the Form1_KeyDown event, after you set the KeyPreview property of the form to True And you need to change the If statement a bit but I'm sure you can get it 
VB Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Right Then
MsgBox("a")
End If
End Sub
Has someone helped you? Then you can Rate their helpful post. 
-
Jun 30th, 2005, 03:26 PM
#3
Thread Starter
Lively Member
Re: hotkeys
fank yoo ber mush.
i have never heard of "e". probably because i am in mid-migration to .net
but how do i get it to type the text in textbox1 over again?
Last edited by ader10; Jun 30th, 2005 at 03:38 PM.
-
Jun 30th, 2005, 04:48 PM
#4
-
Jun 30th, 2005, 06:46 PM
#5
Re: hotkeys
 Originally Posted by ader10
fank yoo ber mush.
i have never heard of "e". probably because i am in mid-migration to .net
but how do i get it to type the text in textbox1 over again?
Notice that your Timer.Tick event handler has an "e" argument as well. Every event handler has a very similar signature: sender As Object, e As EventArgs, but the type of e can be different, depending on the type of event. Whatever its type, it holds information specific to the event, while the sender is the object that raised the event.
Now to your issue. Obviously you want something to happen when you press F7. What exactly do you want to happen and under what circumstances? Are you aware that you can assign shortcut keys to menu items? This may not be applicable in your case, but if the action you want to perform corresponds to a menu option then it is the simplest way to achieve what you want.
-
Jul 1st, 2005, 10:50 AM
#6
Thread Starter
Lively Member
Re: hotkeys
this should answer both of your questions.
 Originally Posted by manavo11
Sorry, but I don't understand what you mean by "how do i get it to type the text in textbox1 over again"... Could you explain that again?
Thanks
i have textbox1 and timer1.
i want the text in textbox1 to be typed automatically by the computer and then have the computer press enter by using sendkeys when i press f7
-
Jul 1st, 2005, 08:12 PM
#7
Re: hotkeys
first set your form property keypreview to true.
just like manavo11's code
VB Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.F7 Then
MsgBox("a")
End If
End Sub
-
Jul 1st, 2005, 08:56 PM
#8
Re: hotkeys
First of all, are you using VB 2005? I notice the My.Computer.Keyboard.Sendkeys and think that looks like .NET 2.0. If that is the case, it is always best to mention it from the outset. VS.NET 2003 and .NET 1.1 are still the standards and most people will assume you are using them unless you say otherwise.
As for your question, I don't really see why you are trying to equate the F7 key with the ENTER key. Why doesn't the user just hit the ENTER key? Otherwise, set the TextBox's Text in the Timer's Tick event handler and simulate your key press in the Form's KeyDown event handler, as suggested by others.
-
Jul 2nd, 2005, 09:15 AM
#9
Thread Starter
Lively Member
Re: hotkeys
 Originally Posted by jmcilhinney
First of all, are you using VB 2005? I notice the My.Computer.Keyboard.Sendkeys and think that looks like .NET 2.0. If that is the case, it is always best to mention it from the outset. VS.NET 2003 and .NET 1.1 are still the standards and most people will assume you are using them unless you say otherwise.
As for your question, I don't really see why you are trying to equate the F7 key with the ENTER key. Why doesn't the user just hit the ENTER key? Otherwise, set the TextBox's Text in the Timer's Tick event handler and simulate your key press in the Form's KeyDown event handler, as suggested by others.
ehmmm... thats not what i am trying to do. (yes i am using vb2005. but i use both.)
i dont get the second part of your post probly because you dont get my post.
let me explain it with more detail.
•••••••••••••••••_____________
i have textbox1. [this is textbox1]
i have timer1. this is timer1: (+)
this is my keyboard key, f7. [F7]
•••••••••••••••••
when i press [F7], i want the text in textbox1 to be "typed by the computer" and then have the computer type the [enter] key immediately after typing the text. i want this to keep happening forever at a timed interval (eg, 3 seconds apart) until i press [F7] again.
[F7] is my toggle key to start/stop typing then pressing enter.
so if i have "asdf" in the textbox, and i have notepad open, and if i run the program and set the window focus on notepad, the text should appear in notepad's text box.
asdf
asdf
asdf
asdf
asdf
asdf
***•••*** then i want to stop it. so i go to the taskbar, press the program's button to get focus on the program, and press [F7] to stop the text from typing.
remember, [F7] is my toggle key to start/stop typing then pressing enter.
"sendkeys Sends one or more keystrokes to the active window, as if typed on the keyboard."
if you still dont understand, just yelp.
-
Jul 2nd, 2005, 09:38 AM
#10
Re: hotkeys
Ahhhh... now I get it. You pretty much had it to start with. Remove the If statement form your Tick event handler and just enable and disable the Timer in the form's KeyUp (or KeyDown) event handler:
VB Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
SendKeys.Send(Me.TextBox1.Text)
SendKeys.Send("{ENTER}")
End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = Keys.F7 Then
'Toggle the timer's state.
Me.Timer1.Enabled = Not Me.Timer1.Enabled
End If
End Sub
Make sure that the form's KeyPreview property is set to True. You may also want to provide some visual cue to indicate whether the Timer is enabled or not.
-
Jul 2nd, 2005, 10:04 AM
#11
Thread Starter
Lively Member
Re: hotkeys
congratulations!
you win the prize! you win a gmail account, if you dont have one.
pm me.
the complete code at the end was leeched, but who cares? it works now.
this is my complete code:
VB Code:
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Type what is in textbox1.
SendKeys.Send(Me.TextBox1.Text)
'Press enter immediately after
SendKeys.Send("{ENTER}")
End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = Keys.F7 Then
'Toggle the timer's state.
Me.Timer1.Enabled = Not Me.Timer1.Enabled
'If F7 is pressed, timer1.enabled is switched.
End If
End Sub
End Class
now i need to tackle transparency and the "boss key"
but i wont have problems with that, i think...
-
Jul 2nd, 2005, 09:28 PM
#12
Re: hotkeys (fixed)
Just keep in mind that SendKeys.Send causes behaviour exactly as though you used the keyboard. If some other application gets the focus while your Timer is enabled, the key presses will get sent to it instead of the one you want.
-
Jul 4th, 2005, 02:32 PM
#13
Thread Starter
Lively Member
Re: hotkeys (un-fixed)
it doesnt work in visual basic .net 2003 standard.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|