-
Mar 4th, 2009, 12:59 AM
#1
Thread Starter
Addicted Member
How to "sendkeys" with "alt" button?
Hello,
I'd like to send keys ("sendkeys" function) to one (or more) of the opened windows on the desktop.
The key is consisted of Alt+F6 buttons.
I know this code - but how to add the "Alt" button? Do you know for other or better code?
Thanks in advance!
Code:
Option Explicit
Dim wshShell
Dim intCount
'Open notepad
Set wshShell= CreateObject("WScript.Shell")
wshShell.Run "clearexplorer g:\views\tg_ClearCheck_1.0_int_2"
'Wait a second before we do anything
WScript.sleep 1000
intCount=0
'Send the keys to notepad application
Do While intCount <= 10
wshShell.SendKeys "Line No: "
wshShell.SendKeys intCount
wshShell.SendKeys "{F6}" ' I have to add "Alt" button!
intCount = intCount + 1
Loop
'Quit
WScript.Quit
-
Mar 4th, 2009, 02:54 AM
#2
Re: How to "sendkeys" with "alt" button?
from msdn
SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 4th, 2009, 07:51 AM
#3
Re: How to "sendkeys" with "alt" button?
One note of caution...if you move to Vista, SendKeys is no longer going to work for you.
-
Mar 4th, 2009, 02:01 PM
#4
Re: How to "sendkeys" with "alt" button?
>Vista, SendKeys is no longer going to work for you
SendKeys did not work under beta versions of Vista but in RC1 and SP1 but it works pretty much as before in .exes; the occasional line may need a tweak but that's all.
Sendkeys will give you an Error 70 Permission denied under the VB6 IDE in Vista, something like the following will overcome that;
Code:
Public Sub Sendkeys(Text$, Optional wait As Boolean = False)
Static init As Boolean, IsIDEUnderVista As Boolean, WshShell As Object
'wrapper for Sendkeys which does not cause an Error 70 in the IDE under Windows Vista
'Errors due to WScript disablement on the OS can only happen under the IDE
'Extra overhead for the WshShell object is only required under the IDE
If Not init Then
If IsDevEnv() Then
IsIDEUnderVista = (OsVersion() >= 6)
If IsIDEUnderVista Then Set WshShell = CreateObject("WScript.Shell")
End If
init = True
End If
If Not IsIDEUnderVista Then
VBA.Sendkeys Text$, wait
Else
WshShell.Sendkeys Text$, wait
End If
End Sub
You are left to devise your own IsDevEnv() and OsVersion() functions.
Last edited by Magic Ink; Mar 4th, 2009 at 06:49 PM.
-
Mar 4th, 2009, 03:54 PM
#5
Thread Starter
Addicted Member
Re: How to "sendkeys" with "alt" button?
Thank you very much.
I forgot to ask - how do I send the keys to an already running application? In the examples above, a new object is created and then "sendkeys" are executed. I just want to find an already running app (e.g. "notepad") and then send it keys.
Thanks again!
-
Mar 4th, 2009, 04:03 PM
#6
Re: How to "sendkeys" with "alt" button?
try appactivate
otherwise search on findwindow API
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 5th, 2009, 07:43 AM
#7
Thread Starter
Addicted Member
Re: How to "sendkeys" with "alt" button?
Thank you very much.
However, I tried to use appactivate and findwindow functions, but I can't find how to find activated window (not to open a new one) and then send him keys. Do you have such an example?
Thanks again
-
Mar 30th, 2017, 06:04 PM
#8
Junior Member
Re: How to "sendkeys" with "alt" button?
dim wshShell: Set wshShell= CreateObject("WScript.Shell")
if not(wshShell is nothing) then
wshShell.sendkeys "%(F6)"
doevents
set wshShell = nothing
end if
works perfectly, just make sure you first set focus to the app you want to send keys to.
〘SCRAPER〙software that extracts, organizes and displays data from the web.
〘BOT〙software that automates and speeds up tasks on the web, mimicking human behavior.
-
Mar 30th, 2017, 06:43 PM
#9
Re: How to "sendkeys" with "alt" button?
Examples of things we do not discuss here:
〘SCRAPER〙software that extracts, organizes and displays data from the web.
〘BOT〙software that automates and speeds up tasks on the web, mimicking human behavior.
The first almost always violates a site's terms of use, making such discussions dubious under this site's terms anyway. The second almost always violates the terms here.
-
Mar 30th, 2017, 07:10 PM
#10
Re: How to "sendkeys" with "alt" button?
This thread is eight years old. Most likely, the OP has moved on by now.
My usual boring signature: Nothing
-
Mar 30th, 2017, 08:27 PM
#11
Hyperactive Member
Re: How to "sendkeys" with "alt" button?
Can SendKeys be substituted using SendMessage with "%{F$}"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|