473,394 Members | 1,935 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,394 software developers and data experts.

How to provide shortcut keys for controls like text box,button

sujathaeeshan
Hi all,

I need to provide shortcut keys for controls like text box and buttons etc...
That is i dont want to go for tabspace or mouse click for perticular controls..
By having shortcut keys i need to go for specifeid controls(textbox,button)...

Is there any way to provide shotcut keys for controls.....or built in property values.....


could any anoe help me out of this query...
Feb 16 '08 #1
16 25554
QVeen72
1,445 Expert 1GB
Hi,

For Buttons You can Change the Caption:

&Save

So, cmdsave_Click will be fired, when you press "Alt + S" on the form..

For TextBoxes, you have to code..

REgards
Veena
Feb 16 '08 #2
lotus18
866 512MB
If you want the textbox or any control to be on focus, with an appropriate shortcut key and keypress event

Expand|Select|Wrap|Line Numbers
  1. <ControlName>.SetFocus
  2.  
Feb 16 '08 #3
mafaisal
142 100+
Hello

Firstly Set Forms Property Keypreview True
Then Set All Controls in the Form have regular TAbIndex

Then in Form keydown event
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  2.  sendkeys vbtab
  3. End Sub
  4.  
Hi all,

I need to provide shortcut keys for controls like text box and buttons etc...
That is i dont want to go for tabspace or mouse click for perticular controls..
By having shortcut keys i need to go for specifeid controls(textbox,button)...

Is there any way to provide shotcut keys for controls.....or built in property values.....


could any anoe help me out of this query...
Feb 16 '08 #4
olseni
19
Hi all,
Sorry to "butt in" on this, but I have the same issue, and the answers so far does not seem to do the trick, or maybe I am doing it wrong....

If I have a form with a button called Open Details which opens another form. If I wish to use a shortcut key (instead of clicking the button with the mouse), e.g. Alt+O, how do I do that ? Is there functionality, or code to be used ?

Thanks
Best regards
Ingrid
Feb 28 '08 #5
kadghar
1,295 Expert 1GB
Hi all,
Sorry to "butt in" on this, but I have the same issue, and the answers so far does not seem to do the trick, or maybe I am doing it wrong....

If I have a form with a button called Open Details which opens another form. If I wish to use a shortcut key (instead of clicking the button with the mouse), e.g. Alt+O, how do I do that ? Is there functionality, or code to be used ?

Thanks
Best regards
Ingrid
Depending on the version you can use Veena's solution, but lotus' one is more general, add in the form's keypress event the code to call the click event's sub of the button, for example, something like this in te form keydown button will do:

Expand|Select|Wrap|Line Numbers
  1. If KeyCode = Asc("O") And Shift = 2 Then CommandButton1_Click
add it to the controls that can be selected, so when they're selected and you press Ctrl+O the command1_click sub will be called. It'll be some copypaste work if you have many commands, but is the simplest way for few.

Note 2 is the value of Ctrl. check the help file or the object browser to see the shift or alt values, you can also use vb constants.

HTH
Feb 28 '08 #6
Killer42
8,435 Expert 8TB
Both people who have the problem, please tell us what version of VB you're using.
Feb 28 '08 #7
debasisdas
8,127 Expert 4TB
If using VB 6.0 then it is quite easy to set focus for text boxes.

1.Use a label control for the labeling of the textbox .
2.UseMnemonic should be set to true for the label (default).
3.Use & to assign the Mnemonic.
4.Set the tab index of the textbox to one more than the corresponding label.

When you try set the focus on the label using the Mnemonic character and since label is a static control so could not receive the focus , focus will be set to next control in higher tab index order.
Feb 28 '08 #8
Killer42
8,435 Expert 8TB
Thanks Debasis. Exactly what I would have said, if I'd had time. :)
Feb 28 '08 #9
Hi,

Just provide the &Open Details at the text property of the button.
while running the form if u fired Alt+O ,it automatically fires the function of button(open details)-- which opens another form.

Regards
suji
Mar 2 '08 #10
olseni
19
Hi all,
thanks a lot for the many replies, and sorry for not being in here for so long, however now I am back and can reply to some of the suggestions and questions.

I am using VB 6,5 with Access 2007.

Thanks HTH for your suggestion code, I just tried it out, but it doesnt seem to work, or I am doing it wrong. I used the code you provided and set it into the OnKeyDown property of the Form as

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = Asc("O") And Shift = 2 Then Command142_Click
End Sub

Command142 being the button I want to open. But when I press Ctrl+O nothing happens..... what am I doing wrong ?

Suji, I am not quite sure I understand your suggestion, could you please elaborate ?

I hope you can still help me....
Thanks in advance
Best regards
Ingrid

Apr 3 '08 #11
kadghar
1,295 Expert 1GB

Thanks HTH for your suggestion code, I just tried it out, but it doesnt seem to work, or I am doing it wrong. I used the code you provided and set it into the OnKeyDown property of the Form as

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = Asc("O") And Shift = 2 Then Command142_Click
End Sub

Command142 being the button I want to open. But when I press Ctrl+O nothing happens..... what am I doing wrong ?
HTH = hope that helps
Call me Kad

Its because as your form has many controls, when you initilialize the form, what is selected is not the form, but another control. So for Ctrl-O to work it has to be in the KeyDown event of the selected control. (so you can write it on every control key down event)

HTH (again ^.^)
Apr 3 '08 #12
olseni
19
Hi Kad,
Sorry about the HTH :-)
Anyway I tried it and it works when I am already placed on the command, however is there a way of using shortcut keys to activate a command, or go to a specific field without being placed on the command already ?

My reason for wanting this function is that I will use it as shortcuts for a user, being anywhere in the form, and instead of using the mouse, or the tabs to "get there" I would want to use a shortcutkey.... sorry if I explained my issue wrong earlier....

Thanks in advance
Best regards
Ingrid
Apr 3 '08 #13
olseni
19
Close of this issue since solution has been provided
Apr 15 '08 #14
smartchap
236 100+
I think this is the final solution and will be beneficial for everyone:
Use the code below:

Expand|Select|Wrap|Line Numbers
  1. Dim A As Integer
  2. Dim B As Integer
  3.  
  4. Sub SetControlFocus(KeyCode As Integer, Shift As Integer)
  5.     If KeyCode = Asc("A") And Shift = 2 Then Command1_Click
  6.     If KeyCode = Asc("B") And Shift = 2 Then Command2_Click
  7.     If KeyCode = Asc("D") And Shift = 2 Then Text1.SetFocus
  8.     If KeyCode = Asc("E") And Shift = 2 Then Text2.SetFocus
  9.     If KeyCode = Asc("F") And Shift = 2 Then Text3.SetFocus
  10.     If KeyCode = Asc("G") And Shift = 2 Then Option1.SetFocus
  11.  
  12.     'MsgBox "OK"
  13. End Sub
  14.  
  15. Private Sub Command1_Click()
  16.     MsgBox "Clicked Command Button 1"
  17. End Sub
  18.  
  19. Private Sub Command2_Click()
  20.     MsgBox "Clicked Command Button 2"
  21. End Sub
  22.  
  23. Private Sub Option1_KeyDown(KeyCode As Integer, Shift As Integer)
  24.     A = KeyCode: B = Shift
  25.     If B <> 0 Then
  26.         If B = 2 And A <> 17 Then
  27.             Call SetControlFocus(A, B)
  28.         End If
  29.     End If
  30. End Sub
  31.  
Write the code in Option1_KeyDown event in every control's key down event and the results will be as required. If satisfied please post reply.
Apr 26 '08 #15
very good and helpful
Jan 4 '17 #16
very helpful and successfully work
Jan 4 '17 #17

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

Similar topics

2
by: Nick | last post by:
In VS 2003 and VS 2005 beta 2 I am trying to write a simple program. It has a datagrid and a textbox along with a menubar. There is a command in the menu bar which is "Run Query" and has the...
0
by: Saper\(ek\) | last post by:
this is a strange behavior of buttons with shortcut keys, when You have a datagrid on a form and some buttons with shortcut keys. When You click on the datagrid (anywhere but the cells, free space,...
1
by: Aaron | last post by:
How can I add a shortcut key to a button in a windows app.? for example i have a button called submit and right now the only way to execute its function is to left click the button. I would like...
1
by: BuddyWork | last post by:
Hello, If you copy the source code from this post into seperate files as stated, and compile the code. Now to reproduce run the code in debug. 1. Press the Client button. 2. Put the cursor...
5
by: Shailja | last post by:
Hi, How to provide shortcut keys to toolbar button? If i write &New in caption property of button, which key should i use with N? Kindly let me know.
0
by: thirunavukarasukm | last post by:
Hai... How to Usercontrols with Shortcut Keys... I am creating one windows apllication.. the apllication contain many form.. in one form i am used one usercontrol(parent control)..
4
karthickbabu
by: karthickbabu | last post by:
Hi How can i create shortcut keys for Button Controls in vb.net. I am using MDI form and Child Form. I want to create shortcut key for button in ChildForm. Actually i created but when i press...
1
sujathaeeshan
by: sujathaeeshan | last post by:
Hi all, I need to provide shortcut keys for controls like text box and buttons etc... That is i dont want to go for tabspace or mouse click for perticular controls.. By having shortcut keys i...
2
by: Andrus | last post by:
If focused control is ReadOnly, menu shortcut key is ignored. To reproduce, run code below, press Ctrl+E. Note that message box does not appear. This issue blocks Ctrl+E usage in application....
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a textbox containing a listview of items. I would like to set it up so that when that textbox has the focus and I press ctl-A from the keyboard it selects all the items. Dealing...
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
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.