Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

While Key press is false question

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
US
I want to run a simple loop that happens until the escape key is pressed, however I can't find any useful information.

The code looks like this -

While appliation.keypress "{Esc}" = false

Do

loop

Wend

Anyone know what I am doing wrong?
 
AFAIK, it does not work that way at all. Otherwise the application would be testing if EVERY key was False (or not). It works the other way. When ESC is pressed then something can happen.

 
Check out GetAsyncKeyState(VK_ESCAPE).

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Wasn't able to get the GetAsynKeyState to work with this scenario.

Basically I am running a while statment that needs to be interrupted. If Esc is pressed the code flips forward through several rows of information before stopping and if the escape isn't held down the macro continues.
 
Something like the following:
Code:
[blue]Option Explicit

Public EscPressed As Boolean

Public Sub Example()
    EscPressed = False
    Application.OnKey "{ESC}", "OpCancel"
    While Not EscPressed
        [green]'Your code here[/green]
        DoEvents
    Wend
    Application.OnKey "{Esc}", ""
    MsgBox "And we have escaped ..."
End Sub

Public Sub OpCancel()
     EscPressed = True
End Sub[/blue]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top