[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2004-03-31
8
Medium Priority
?
2,063 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
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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

649 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