Solved

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

Posted on 2004-03-31
8
2,032 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
  • 4
  • 2
  • 2
8 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 125 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now