?
Solved

sendkeys ^{ESC} (Control key + Escape key) not working

Posted on 2004-03-31
8
Medium Priority
?
2,056 Views
Last Modified: 2007-12-19
Hi,

Im using VB6, my OS is XP.

Basically i want to bringup an existing file (say .txt or .xls file) and wish to perform some keystrokes in them. I use sendkeys function to send keystrokes to the file.
When i open the file manually by double clicking on it, then everything works fine.

Now, I want to bringup this file automatically and send keystrokes to it.

I thaught thar giving the full file path and name in START>RUN then the file might come up.
So i sent keystroke ^{ESC} (Control Escape) to invoke the START menu and then sentkey "R" to invoke RUN. But this operation is not working.

Can anyone help, y this sendkeys ^{ESC} is not working? or is there any other way to bringup the file which i need.

Thanks,
Kumara Krishnan.
0
Comment
Question by:kumarakrishnan
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 375 total points
ID: 10723289
Use :

Shell "notepad.exe c:\yourfile.txt"
0
 
LVL 14

Expert Comment

by:aelatik
ID: 10723309
Private Sub Form_Load()
Shell "notepad.exe c:\yourfile.txt", vbMaximizedFocus
End Sub
0
 
LVL 14

Expert Comment

by:aelatik
ID: 10723383
Or use api to launch any extension with its associated program.

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Form_Load()
ShellExecute Me.hwnd, "open", "c:\out.txt", 0, "c:\", 3
End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:kumarakrishnan
ID: 10723436
Ya this is working, but when i try to send key ctrl esc why the start menu is not invoked? any suggesion on this? I need to go into start programs and click on some app.
0
 
LVL 4

Expert Comment

by:sokolovsky
ID: 10723442
Use this:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
Private Sub Form_Load()
    Dim strMyFile As String
    strMyFile = "c:\eula.txt" 'Path to your file
    ShellExecute Me.hwnd, "open", strMyFile, vbNullString, "C:\", SW_SHOWNORMAL
End Sub
0
 
LVL 14

Expert Comment

by:aelatik
ID: 10723497
Using sendkeys is very tricky ( and messy ).
it requires windows to focus on the target you wish to send keystrokes to.
I cannot explain why it doesn't works. ( I never use it because of that )
0
 
LVL 1

Author Comment

by:kumarakrishnan
ID: 10723625
Thankyou Aelatik,

it worked.

Kumara Krishnan
0
 
LVL 4

Expert Comment

by:sokolovsky
ID: 10723664
If you still need to open Start menu and send keys, use this:

'Simple Form
Const VK_CONTROL = &H11
Const VK_ESCAPE = &H1B
Const KEYEVENTF_KEYUP = &H2
Const INPUT_MOUSE = 0
Const INPUT_KEYBOARD = 1
Const INPUT_HARDWARE = 2
Private Type MOUSEINPUT
  dx As Long
  dy As Long
  mouseData As Long
  dwFlags As Long
  time As Long
  dwExtraInfo As Long
End Type
Private Type KEYBDINPUT
  wVk As Integer
  wScan As Integer
  dwFlags As Long
  time As Long
  dwExtraInfo As Long
End Type
Private Type HARDWAREINPUT
  uMsg As Long
  wParamL As Integer
  wParamH As Integer
End Type
Private Type GENERALINPUT
  dwType As Long
  xi(0 To 23) As Byte
End Type
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Form_Activate()
    Call OpenStart
    DoEvents
    SendKeys "p", True 'If you have "Programs group"
End Sub
Sub OpenStart()
    Dim GInput(0 To 3) As GENERALINPUT
    Dim KInput As KEYBDINPUT
    KInput.wVk = VK_CONTROL 'the key we're going to press
    KInput.dwFlags = 0 'press the key
    GInput(0).dwType = INPUT_KEYBOARD   ' keyboard input
    CopyMemory GInput(0).xi(0), KInput, Len(KInput)
    KInput.wVk = VK_ESCAPE  ' the key we're going to realease
    'KInput.dwFlags = KEYEVENTF_KEYUP  ' release the key
    KInput.dwFlags = 0  ' release the key
    GInput(1).dwType = INPUT_KEYBOARD  ' keyboard input
    CopyMemory GInput(1).xi(0), KInput, Len(KInput)
   
    KInput.wVk = VK_CONTROL 'the key we're going to press
    KInput.dwFlags = KEYEVENTF_KEYUP 'press the key
    GInput(2).dwType = INPUT_KEYBOARD   ' keyboard input
    CopyMemory GInput(2).xi(0), KInput, Len(KInput)
    KInput.wVk = VK_ESCAPE  ' the key we're going to realease
    KInput.dwFlags = KEYEVENTF_KEYUP  ' release the key
    GInput(3).dwType = INPUT_KEYBOARD  ' keyboard input
    CopyMemory GInput(3).xi(0), KInput, Len(KInput)
    'send the input now
    Call SendInput(4, GInput(0), Len(GInput(0)))
End Sub
Private Sub SendKey(bKey As Byte)
    Dim GInput(0 To 1) As GENERALINPUT
    Dim KInput As KEYBDINPUT
    KInput.wVk = bKey  'the key we're going to press
    KInput.dwFlags = 0 'press the key
    'copy the structure into the input array's buffer.
    GInput(0).dwType = INPUT_KEYBOARD   ' keyboard input
    CopyMemory GInput(0).xi(0), KInput, Len(KInput)
    'do the same as above, but for releasing the key
    KInput.wVk = bKey  ' the key we're going to realease
    KInput.dwFlags = KEYEVENTF_KEYUP  ' release the key
    GInput(1).dwType = INPUT_KEYBOARD  ' keyboard input
    CopyMemory GInput(1).xi(0), KInput, Len(KInput)
    'send the input now
    Call SendInput(2, GInput(0), Len(GInput(0)))
End Sub
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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
Course of the Month13 days, 8 hours left to enroll

801 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