473,405 Members | 2,171 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,405 software developers and data experts.

how to link a key on keyboard to a function

547 512MB
When i press the "+" (ascikey 43)on my keyboard, i would like a function to work in a specific form called "RaceSetupXCF".
The code to be linked to "+" is below. The "+" must not be added to the fields of this form when pressing it.It must only work with the code below when the form is open.
Expand|Select|Wrap|Line Numbers
  1. Dim iRetValue As Long
  2.  If KeyAscii = 43 Then iRetValue = sndPlaySound(CurrentProject.Path & "\bell.wav", SND_ASYNC)
any suggestions please?
thx
May 2 '11 #1

✓ answered by TheSmileyCoder

You have to look at your FORMS Key_press event. For example:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyPress(KeyAscii As Integer)
  2.     If KeyAscii = 43 Then
  3.         iRetValue = sndPlaySound(CurrentProject.Path & "\bell.wav", SND_ASYNC)
  4.     End If
  5.  
  6.     'If you want to cancel out any other action 
  7.     '  that might come from the key (Such as 
  8.     '  form navigation, or typing in fields), 
  9.     '  you can clear the key by the following code:
  10.     KeyAscii = 0
  11.  
  12. End Sub
For the form to to receive key_press BEFORE the control that has the focus, you need to set the forms KeyPreview value to True.

2 1886
neelsfer
547 512MB
Thought i got it working in the specific subform on main form using
Expand|Select|Wrap|Line Numbers
  1. Dim iRetValue As Long
  2. If Len(Nz(Me![RaceNumber].Text, 0)) = 0 And KeyAscii = 43 Then KeyAscii = 0 And iRetValue = sndPlaySound(CurrentProject.Path & "\bell.wav", SND_ASYNC)
  3.    Cancel = True
but my application crashes
But after adding error trapping code it seems to work again
May 2 '11 #2
TheSmileyCoder
2,322 Expert Mod 2GB
You have to look at your FORMS Key_press event. For example:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyPress(KeyAscii As Integer)
  2.     If KeyAscii = 43 Then
  3.         iRetValue = sndPlaySound(CurrentProject.Path & "\bell.wav", SND_ASYNC)
  4.     End If
  5.  
  6.     'If you want to cancel out any other action 
  7.     '  that might come from the key (Such as 
  8.     '  form navigation, or typing in fields), 
  9.     '  you can clear the key by the following code:
  10.     KeyAscii = 0
  11.  
  12. End Sub
For the form to to receive key_press BEFORE the control that has the focus, you need to set the forms KeyPreview value to True.
May 2 '11 #3

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

Similar topics

2
by: Dennis M. Marks | last post by:
I have seen partial answers to the following question but I am not sure of the best approach. I have a page that will only work with javascript. The link to the page indicates that. Within the...
2
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
2
by: SAL | last post by:
I would like to create a VB.net function, that builds a dynamic hyperlink using System.Web.UI.WebControls.HyperLink, but I can not find any examples on how to generate a dynamic hyperlink. Has...
2
by: farriswheel | last post by:
Hello All, I am trying to link a date function to a text box. I go into text box click on expression builder and insert the date function into the after update tab when I turn on the form I don't...
1
by: ahoway | last post by:
I am having problems deleting a node from a link list. I need to delete the node which contains the number six. This is what I have so far..... Thank you in advance. #include <iostream>...
2
by: Alam | last post by:
Hello All, Just couple of simple questions if someone can help: 1. I have a combobox and its properties are set as: Autocomplete mode = suggestappend Autocomplete source = List items Is there an...
1
by: safuk2233 | last post by:
I need a function derived from: javascript: myLightWindow.activateWindow({href: \''. DIR_WS_IMAGES. $product_info .'\', title: \'Waiting for the show to start in Las Vegas\', author:...
2
by: Aykut Canturk | last post by:
there's an aspnet site. some pages are html and cannot be changed. (no javascript nor links can be changed). these pages have links. for example a.html calls b. html like: <a href="b.html"page...
3
by: Levale | last post by:
Hello I'm new here. I need a function in 'C' that just pauses until the user hit's the enter key. I wanted to use getchar() however that function opens a stdio window which closes the main user...
2
by: tmartiro | last post by:
Hi guys, I want to create link attach function like it implemented in facebook or google buzz. Do you know how to create this kind of stuff? Thanks in advance
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.