Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to send 'F1' key as ASCII character?

Posted on 2010-08-18
14
Medium Priority
?
897 Views
Last Modified: 2012-05-10
Another related question, what if I'm trying to send the key F1, which is a combination of several characters, i.e. Chr(27) & "O" & "P"?
0
Comment
Question by:teeling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33462604
from what I know, the function keys don't have ASCII correspondants ...
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33462606
if you want to "send" the key to the active window, then it would be:

SEND "{F1}"
0
 

Author Comment

by:teeling
ID: 33462610
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33462620
then, as I feared, the answer is: you cannot do that directly.
the only option is to have a coded string (like the Send function does), which needs to be interpreted ...
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 33465334
In VB (such as VB 6), use
SendKeys "{F1}"
to send F1 to the program and control that currently has the focus.
0
 

Author Comment

by:teeling
ID: 33470674
angellll: Can you show me roughly what you mean?

Lethauser: I am using VBA. Sending 'F1' does not work.
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 33470895
Sorry. There really should be a box to check or something on these questions that tells us what language people are using.
0
 

Author Comment

by:teeling
ID: 33470908
Not your fault. I should have clarified this at the beginning.
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 33470960
Believe me, you are not the first. I have lost count of how many times I have given a VB 6 solution to a question and then been told by the person that it does not work because they are using VBA or VB.net, or something else. I think that Experts-exchange should have some kind of check box on all programming questions so that people can (have to, in fact) specify which Visual Basic language they are using.
0
 

Author Comment

by:teeling
ID: 33471755
Anyone has got any idea how to solve this problem? Thanks.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33479613
as I said: F1 key does not have an ASCII code.
so, you have to define some other ascii code combination to represent F1, aka the receiving side of the data stream has to look for this and say: this is F1 ...

for example:
sending "{F1}" is to be understood as "F1", while sending "{{}" shall be read on the receiving side as "{"

0
 

Author Comment

by:teeling
ID: 33482484
I found a way to get around this problem.data is obtained from the Excel sheet.

Function MySend(ByVal data As String)
'    DoEvents
    If LCase(data) = "chr(13)" Then data = Chr(13)
    
    If LCase(data) = "chr(27)" Then data = Chr(27)

    If LCase(data) = "chr(27)&o&p" Then
        wsTCP.SendData (Chr(27) & "O" & "P")
        Exit Function
    End If
    
    wsTCP.SendData data
    
End Function

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33482502
isn't that exactly what I suggested? ...
0
 

Author Comment

by:teeling
ID: 33482507
Yupe. Thanks for your suggestion.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question