473,395 Members | 1,488 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.

Programmatically Press Key - How to do it?

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 programmatically pressing the F1 key continuously. The thing is, I don't know the code to make it press a key for you. Any help?
Apr 20 '07 #1
15 26417
Killer42
8,435 Expert 8TB
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 programmatically pressing the F1 key continuously. The thing is, I don't know the code to make it press a key for you. Any help?
In VB6 it was SendKeys. You could try looking in the upgrade info for things that have changed.
Apr 21 '07 #2
SammyB
807 Expert 512MB
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 programmatically 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)
Expand|Select|Wrap|Line Numbers
  1. System.Windows.Forms.SendKeys.Send("{F1}")
Don't ask about the braces: who designs this VB stuff?
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.aspx
Apr 21 '07 #3
Killer42
8,435 Expert 8TB
It survived. :( (I think that using it indicates poor design)
I disagree. You might just as well say the same about any statement. It depends how you use it.
Expand|Select|Wrap|Line Numbers
  1. System.Windows.Forms.SendKeys.Send("{F1}")
Don't ask about the braces: who designs this VB stuff?
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.aspx
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.
Apr 22 '07 #4
SammyB
807 Expert 512MB
I 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.
A better reference for SendKeys is http://msdn2.microsoft.com/en-us/lib...48(vs.80).aspx.

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.
Apr 23 '07 #5
Killer42
8,435 Expert 8TB
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.
So what you're saying is that setting up a string as
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.
Apr 23 '07 #6
SammyB
807 Expert 512MB
So what you're saying is that setting up a string as
StrThingy = "ABC" & vbKeyF1
is simpler than
StrThingy = "ABC{F1}"
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.

I still don't agree.
See http://despair.com/compromise.html ;)

Also, I'm not sure VB had anything to do with it - it may be due to other constraints.
Yea, it's a Net Framework thing. Works in C# also. :rolleyes:
Apr 23 '07 #7
Killer42
8,435 Expert 8TB
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.
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... :p

Or perhaps you should use a bigger font or something.


See http://despair.com/compromise.html
No can do. It's blocked as a "shopping" site.

Yea, it's a Net Framework thing. Works in C# also.
:confused: It's been around since years before the .Net framework was even thought of.
Apr 23 '07 #8
SammyB
807 Expert 512MB
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... :p
Maybe we should just use ones and zeros!

"shopping" site.
You've got to find a computer to get there. You'll love it!

It's been around since years before the .Net framework was even thought of.
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. :)
Apr 24 '07 #9
Killer42
8,435 Expert 8TB
Maybe we should just use ones and zeros!
Nah. stick with 1's. They're slimmer, so you don't need as much space.

You've got to find a computer to get there. You'll love it!
Will have a look at home if I remember.

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.
Um... sorry, what point does that prove? :confused:

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.)
Apr 24 '07 #10
SammyB
807 Expert 512MB
Um... sorry, what point does that prove? :confused:
Obvious: if I didn't teach it, you don't need it! :D

Split functions.
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:
Apr 24 '07 #11
Killer42
8,435 Expert 8TB
Obvious: if I didn't teach it, you don't need it!
Oh, of course. Silly of me. :)

The split function is one of the best things that Microsoft gave us.
No argument from me on that point.
BTW, if s = "This is cool", did you know you can use Split(s)(1) to get the "is"?
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.)

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.)
Apr 24 '07 #12
SammyB
807 Expert 512MB
I hate zero-based arrays.
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.
Apr 24 '07 #13
Killer42
8,435 Expert 8TB
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.
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.

Hm... I wonder whether Option Base still works...
Apr 24 '07 #14
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.keydowneventargs(keys.F1)
call formname_keydown(sender,evt)
Apr 24 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Marek Mand | last post by:
How to use generated keyboard events? What I am trying here to do is in onkeyup event handler http://www.hot.ee/idaliiga/braggart/createEventTest.htm generate a (shift)TAB keydown so the...
3
by: kai | last post by:
Hi, All I try to trigger tab key press when enter a string in "customer ID" if its length is six, but I cannot find command to simulate TAB KEY press. PLease help. Thanks a lot Kai
11
by: Zlatko Matić | last post by:
Hello. I have a MS Access front-end working with PostgreSQL database. I have successfully created saved File DSN. My paa-through queries are referring to that file as well as linked tables. But I...
5
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only...
2
by: Vern | last post by:
I've tried the following, and it sets the focus to the tab, but it doesn't put the square box on the tab like it does when you use the mouse to click on a tab. Therefore, when you press the right...
6
by: Ray Booysen | last post by:
Hi all I have a webform with some functionality I need to use. But I need the page to render first. Is there any way to do this? I essentially need to instanciate an instance of the page get...
3
by: oopaevah | last post by:
I want to have a separate button which invokes the "browse" button on an input type=file. In internet explorer the following code works ok, in firefox nothing happens. All I do is call click()...
1
by: Lenny | last post by:
hi I have 10 textboxes in a form named a1, a2, a3, a4,..... a10 when I press a button I want to perform 10 queries. every query should use the value in a text box how can I do it? here is my...
2
by: Tina | last post by:
How can I programmatically navigate a website just as a user would? click on buttons, hyperlinks, etc. I know how to read nodes using XPath but I don't know what classes to use to navigate. I...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.