I'm using Visual Basic 2005 Express Edition. I'm attempting to make a program that, after a button on the form (button1 or whatever I name it), the program will start programmaticall y pressing the F1 key continuously. The thing is, I don't know the code to make it press a key for you. Any help?
Programmatically Press Key - How to do it?
Collapse
X
-
Tags: None
-
In VB6 it was SendKeys. You could try looking in the upgrade info for things that have changed.Originally posted by ShizzMasteRI'm using Visual Basic 2005 Express Edition. I'm attempting to make a program that, after a button on the form (button1 or whatever I name it), the program will start programmaticall y pressing the F1 key continuously. The thing is, I don't know the code to make it press a key for you. Any help? -
It survived. :( (I think that using it indicates poor design)Originally posted by ShizzMasteRI'm using Visual Basic 2005 Express Edition. I'm attempting to make a program that, after a button on the form (button1 or whatever I name it), the program will start programmaticall y pressing the F1 key continuously. The thing is, I don't know the code to make it press a key for you. Any help?
Don't ask about the braces: who designs this VB stuff?Code:System.Windows.Forms.SendKeys.Send("{F1}")
Don't mind the ravings of an old man. ;o)>>> For more info, see the help file, http://msdn2.microsoft.com/en-us/lib...keys.send.aspxComment
-
I disagree. You might just as well say the same about any statement. It depends how you use it.Originally posted by SammyBIt survived. :( (I think that using it indicates poor design)You have a problem with the braces? Why? What would you suggest instead? VB has to have some way to know you didn't want to send an "F" key followed by a "1" key.Originally posted by SammyBDon't ask about the braces: who designs this VB stuff?Code:System.Windows.Forms.SendKeys.Send("{F1}")
Don't mind the ravings of an old man. ;o)>>> For more info, see the help file, http://msdn2.microsoft.com/en-us/lib...keys.send.aspxComment
-
A better reference for SendKeys is http://msdn2.microsoft.com/en-us/lib...48(vs.80).aspx.Originally posted by Killer42I disagree. You might just as well say the same about any statement. It depends how you use it.You have a problem with the braces? Why? What would you suggest instead? VB has to have some way to know you didn't want to send an "F" key followed by a "1" key.
Re braces: An enum seems to me to be better: in VB6, we have vbKeyF1, and in DotNet we have System.Windows. Forms.Keys.F1, so why add another language feature.Comment
-
So what you're saying is that setting up a string asOriginally posted by SammyBRe braces: An enum seems to me to be better: in VB6, we have vbKeyF1, and in DotNet we have System.Windows. Forms.Keys.F1, so why add another language feature.
StrThingy = "ABC" & vbKeyF1
is simpler than
StrThingy = "ABC{F1}"
I still don't agree.
It would be nice if they could be used interchangeably , I suppose. Presumably there was some reason why they wanted to use only normal printable characters in SendKeys. Also, I'm not sure VB had anything to do with it - it may be due to other constraints.Comment
-
I wouldn't say simpler. I just don't see a reason for making the language syntax more complicated when "ABC" & vbKeyF1 was already in place. Plus my eyes are so bad that I cannot tell { from (, so I do not like braces anywhere.Originally posted by Killer42So what you're saying is that setting up a string as
StrThingy = "ABC" & vbKeyF1
is simpler than
StrThingy = "ABC{F1}"
See http://despair.com/compromise.html ;)Originally posted by Killer42I still don't agree.
Yea, it's a Net Framework thing. Works in C# also. :rolleyes:Also, I'm not sure VB had anything to do with it - it may be due to other constraints.Comment
-
Well, obviously the use of any similar-looking characters should be banned in all cases. So, no more "O" or "0", and so on. Wow, this is going to be hard to get used to... :pOriginally posted by SammyBI wouldn't say simpler. I just don't see a reason for making the language syntax more complicated when "ABC" & vbKeyF1 was already in place. Plus my eyes are so bad that I cannot tell { from (, so I do not like braces anywhere.
Or perhaps you should use a bigger font or something.
No can do. It's blocked as a "shopping" site.Originally posted by SammyB
:confused: It's been around since years before the .Net framework was even thought of.Originally posted by SammyBYea, it's a Net Framework thing. Works in C# also.Comment
-
Maybe we should just use ones and zeros!Originally posted by Killer42Well, obviously the use of any similar-looking characters should be banned in all cases. So, no more "O" or "0", and so on. Wow, this is going to be hard to get used to... :p
You've got to find a computer to get there. You'll love it!Originally posted by Killer42"shopping" site.
Ah, this proves my point! I've taught begining & advanced VB6 programming and never heard of it until I read the help file that started this derailing. :)Originally posted by Killer42It's been around since years before the .Net framework was even thought of.Comment
-
Nah. stick with 1's. They're slimmer, so you don't need as much space.Originally posted by SammyBMaybe we should just use ones and zeros!
Will have a look at home if I remember.Originally posted by SammyBYou've got to find a computer to get there. You'll love it!
Um... sorry, what point does that prove? :confused:Originally posted by SammyBAh, this proves my point! I've taught begining & advanced VB6 programming and never heard of it until I read the help file that started this derailing.
In the last couple of months I've come across lots of features of VB6 that I had been unaware of for years - does that prove anything about them? (Example: the Replace and Split functions.)Comment
-
Obvious: if I didn't teach it, you don't need it! :DOriginally posted by Killer42Um... sorry, what point does that prove? :confused:
The split function is one of the best things that Microsoft gave us. BTW, if s = "This is cool", did you know you can use Split(s)(1) to get the "is"? :cool:Originally posted by Killer42Split functions.Comment
-
Oh, of course. Silly of me. :)Originally posted by SammyBObvious: if I didn't teach it, you don't need it!
No argument from me on that point.Originally posted by SammyBThe split function is one of the best things that Microsoft gave us.I did, but only since I encountered it on TSDN a month or three ago. (Of course, in practice it would probably take me a couple of attempts to hit the right word. I would initially expect (1) to return "This" then have to adjust my code. I hate zero-based arrays.)Originally posted by SammyBBTW, if s = "This is cool", did you know you can use Split(s)(1) to get the "is"?
Wish I had known years ago. I have written tons of code to do the work that Split and Replace do. Not that it hasn't been fun, of course. :) After all, what other reason is there for programming?
(By the way, zero-based arrays do have one or two useful purposes. For something like a sort, where you need to swap elements around, the "zeroth" element is handy as a temporary bucket to hold them. Also it's sometimes handy as a place to store metadata related to the array.)Comment
-
Allowing anything but one-based arrays was one of the worst things that Microsoft did. But, the biggest irritation is their inconsistancy: you never know/can remember if an array is zero or one based. DotNet is infinitely more consistent: I only remember one time when I said that something (forgotten what) was inconsistant.Originally posted by Killer42I hate zero-based arrays.Comment
-
I just don't rely on the default. For instance, I would never define an array as MyArray(10). It would be MyArray(1 To 10). At least that way it's spelled out for you, right there.Originally posted by SammyBAllowing anything but one-based arrays was one of the worst things that Microsoft did. But, the biggest irritation is their inconsistancy: you never know/can remember if an array is zero or one based. DotNet is infinitely more consistent: I only remember one time when I said that something (forgotten what) was inconsistant.
Hm... I wonder whether Option Base still works...Comment
-
1. The form's KeyPreview set to be true.
2. In form Keydown event for F1 write what u want to Perform.
3. Then in Button Click event write BelowCode
Dim evt as new System.windows. forms.keydownev entargs(keys.F1 )
call formname_keydow n(sender,evt)Comment
Comment