ITO Posted December 6, 2019 Posted December 6, 2019 I am trying to send a keystroke (SHIFT+1) to an application, but I am unable to do so. As you can see below, I am able to find the window in question, focus it and send the keys. When I run the script, nothing happened but I can send the keystrokes manually thus proving that the application/window has focus. Any whelp would greatly be appreciated. As per below, I have tried many different combinations to no avail. Even tried the "CAPS Lock" key. best, Ito expandcollapse popup;#include "myFunctions.au3" ;#include <GuiComboBox.au3> ;#include <AutoItConstants.au3> ;#include <GuiEdit.au3> Opt("WinTitleMatchMode", 2) ;To use partial match for window title search if WinExists("Level II") Then WinActivate("Level II") EndIf Local $hwnd = WinWaitActive("Level II") ;### Debug MSGBOX ↓↓↓ WinActivate($hwnd) Sleep(500) ; Would like to send Shift + 1 (press 1 while holding SHIFT) tried the following and ;none of them worked ControlSend($hwnd,"","","+1",0) Send("{CAPSLOCK on}",1) ;sent as a test but did'nt work Sleep(500) Send("+1",0) Sleep(500) send("{SHIFTDOWN}1{SHIFTUP}",1) Sleep(500) Send("{SHIFTDOWN}",1) Send("1") Send("{SHIFTUP}",1) Sleep(500) Send("{LSHIFT}1",1) Sleep(500)
Nine Posted December 6, 2019 Posted December 6, 2019 (edited) don't send raw Edited December 6, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
ITO Posted December 6, 2019 Author Posted December 6, 2019 (edited) 10 minutes ago, Nine said: don't send raw Still did not work...Tried that already as u can see in the code Send("+1",0) Edited December 6, 2019 by ITO
Nine Posted December 6, 2019 Posted December 6, 2019 Ya but the rest of your attempts is raw...If Send doesn't work, I don't know what will. You may try send vkeys. Look _WinAPI_Keybd_Event. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
ITO Posted December 6, 2019 Author Posted December 6, 2019 1 hour ago, Nine said: Ya but the rest of your attempts is raw...If Send doesn't work, I don't know what will. You may try send vkeys. Look _WinAPI_Keybd_Event. Never used it before...do you happened to have a snippet, hopefully as it applies to my case ...I have not seen anything regarding sending two keys at once...Thx
ITO Posted December 6, 2019 Author Posted December 6, 2019 1 hour ago, Nine said: Ya but the rest of your attempts is raw...If Send doesn't work, I don't know what will. You may try send vkeys. Look _WinAPI_Keybd_Event. Agree
Nine Posted December 6, 2019 Posted December 6, 2019 _WinAPI_Keybd_Event (0x10, 0) ; shift down _WinAPI_Keybd_Event (0x31, 0) ; 1 down _WinAPI_Keybd_Event (0x31, $KEYEVENTF_KEYUP) ; 1 up _WinAPI_Keybd_Event (0x10, $KEYEVENTF_KEYUP) ; shift up “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
ITO Posted December 6, 2019 Author Posted December 6, 2019 1 hour ago, Nine said: _WinAPI_Keybd_Event (0x10, 0) ; shift down _WinAPI_Keybd_Event (0x31, 0) ; 1 down _WinAPI_Keybd_Event (0x31, $KEYEVENTF_KEYUP) ; 1 up _WinAPI_Keybd_Event (0x10, $KEYEVENTF_KEYUP) ; shift up Thx ... will give it a try
ITO Posted December 6, 2019 Author Posted December 6, 2019 3 minutes ago, ITO said: Thx ... will give it a try I did not get any results ... does it have to be w/ the type of window it is trying to control? I'm lost here, does not make sense
Nine Posted December 6, 2019 Posted December 6, 2019 (edited) Open notepad and run it, you will see the result...Make sure you activate the notepad windows before Edited December 6, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
ITO Posted December 6, 2019 Author Posted December 6, 2019 (edited) 3 minutes ago, Nine said: Open notepad and run it, you will see the result...Make sure you activate the notepad windows before Thx ... it always worked w/ Notepad but not with the app I'm trying to control One thing though it sent the key as String I think to Notepad : !{CAPSLOCK on}!1!!1! instead of KeyStrokes. Edited December 6, 2019 by ITO
Nine Posted December 6, 2019 Posted December 6, 2019 This is the raw thing I was talking about. Read help file Send function carefully. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
ITO Posted December 6, 2019 Author Posted December 6, 2019 1 minute ago, Nine said: This is the raw thing I was talking about. Read help file Send function carefully. As per ur suggestion, I had removed the RAW Flag before running the script
Nine Posted December 6, 2019 Posted December 6, 2019 Ok now, make a snippet of the send you are attempting but to Notepad. A runable snippet so we can see where you are wrong... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
ITO Posted December 6, 2019 Author Posted December 6, 2019 1 minute ago, Nine said: Ok now, make a snippet of the send you are attempting but to Notepad. A runable snippet so we can see where you are wrong... expandcollapse popup;#include "myFunctions.au3" ;#include <GuiComboBox.au3> ;#include <AutoItConstants.au3> ;#include <GuiEdit.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> Opt("WinTitleMatchMode", 2) ;To use partial match for window title search $WinTitle = "Untitled" if WinExists($WinTitle) Then WinActivate($WinTitle) EndIf Local $hwnd = WinWaitActive($WinTitle) ;### Debug MSGBOX ↓↓↓ WinActivate($hwnd) Sleep(500) ; Would like to send Shift + 1 (press 1 while holding SHIFT) tried the following and ;none of them worked ;~ ControlSend($hwnd,"","","+1",0) Send("{CAPSLOCK on}",1) ;sent as a test but did'nt work Sleep(500) Send("+1",0) Send("{LSHIFT}{1}") Sleep(500) send("{SHIFTDOWN}1{SHIFTUP}",0) Sleep(500) Send("{SHIFTDOWN}",0) Send("1") Send("{SHIFTUP}",0) Sleep(500) Send("{LSHIFT}1",0) Sleep(500) Global Const $VK_SHIFTT = 0X10 Global Const $VK_NUMBER_1 = 0X31 Global Const $VK_CTRL = 0x11 _WinAPI_Keybd_Event (0x10, 0) ; shift down _WinAPI_Keybd_Event (0x31, 0) ; 1 down _WinAPI_Keybd_Event (0x31, $KEYEVENTF_KEYUP) ; 1 up _WinAPI_Keybd_Event (0x10, $KEYEVENTF_KEYUP) ; shift up
Nine Posted December 6, 2019 Posted December 6, 2019 (edited) Send("{CAPSLOCK on}",1) Still sending raw... Just remove second parameter of send, it is just confusing you and remove on it is useless ! Edited December 6, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Musashi Posted December 6, 2019 Posted December 6, 2019 9 minutes ago, Nine said: Just remove second parameter of send, it is just confusing you Yes, or use $SEND_DEFAULT as second parameter - just to make it 'visual', even if it is not necessary ([optional], default=0). To enable CAPSLOCK for multiple Send commands, you can use AutoItSetOption("SendCapslockMode", 0) expandcollapse popup#include <AutoItConstants.au3> #include <WinAPISys.au3> Global $hWnd, $iDelay = 300 Run("notepad.exe") If @error Then ConsoleWrite("! >>> Error running Notepad" & @CRLF) Exit EndIf $hWnd = WinWaitActive("[CLASS:Notepad]", "", 5) ; wait 5 seconds for the Notepad window to appear. If WinExists($hWnd) Then ConsoleWrite("+ >>> Notepad-Window exists" & @CRLF) Else ConsoleWrite("! >>> Notepad-Window not exists" & @CRLF) Exit EndIf ; >>> sending keys : AutoItSetOption("SendCapslockMode", 0) ; 0=ignore Send(">>> Tests with function Send <<< : {ENTER}", $SEND_DEFAULT) Send("+1", $SEND_DEFAULT) ; (press 1 while holding SHIFT ==> Result = ! ) Send("{ENTER}", $SEND_DEFAULT) ; *** new line Sleep($iDelay) ; -> {CAPSLOCK on} Send("{CAPSLOCK on}", $SEND_DEFAULT) ; (activate CAPSLOCK) Sleep($iDelay) Send("1", $SEND_DEFAULT) ; (press 1 while {CAPSLOCK on} ==> Result = ! ) Send("{ENTER}", $SEND_DEFAULT) ; *** new line Sleep($iDelay) Send("+1", $SEND_DEFAULT) ; (press 1 while holding SHIFT -> {CAPSLOCK on} ==> Result = 1 Send("{ENTER}", $SEND_DEFAULT) ; *** new line Sleep($iDelay) ; -> {CAPSLOCK off} Send("{CAPSLOCK off}", $SEND_DEFAULT) ; (deactivate CAPSLOCK) Sleep($iDelay) Send("+1", $SEND_DEFAULT) ; (press 1 while holding SHIFT ==> Result = ! ) Send("{ENTER}", $SEND_DEFAULT) ; *** new line Sleep($iDelay) Send(">>> End <<<{ENTER}", $SEND_DEFAULT) WinClose($hWnd) ; to answer the "Save Question" automatically, activate the following lines : ;~ WinWaitActive("[CLASS:#32770]") ;~ Sleep(500) ;~ Send("{TAB}{ENTER}") "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Nine Posted December 6, 2019 Posted December 6, 2019 #include <WinAPISys.au3> #include <WindowsConstants.au3> Local $hWnd = WinActivate("[CLASS:Notepad]") If Not WinWaitActive($hWnd, "", 5) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error activating Notepad") Send("{CAPSLOCK}") ; capslock doesnt work on number key Send ("1") Send("{CAPSLOCK}") Send("+1") ; that work Send("{LSHIFT}1") ; that doesnt work becuase you simply ask left shift to be pressed and release before 1 Send("{SHIFTDOWN}1{SHIFTUP}") ; that work _WinAPI_Keybd_Event (0x10, 0) ; shift down _WinAPI_Keybd_Event (0x31, 0) ; 1 down _WinAPI_Keybd_Event (0x31, $KEYEVENTF_KEYUP) ; 1 up _WinAPI_Keybd_Event (0x10, $KEYEVENTF_KEYUP) ; shift up “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Musashi Posted December 6, 2019 Posted December 6, 2019 (edited) 8 minutes ago, Nine said: Send("{CAPSLOCK}") ; capslock doesnt work on number key Are you sure ? Please check my example ! (press 1 while {CAPSLOCK on} ==> Result = ! ) Edited December 6, 2019 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Nine Posted December 6, 2019 Posted December 6, 2019 11 minutes ago, Musashi said: Are you sure ? Yes “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now