Jump to content

Send() keystrokes not working (SHIFT+1)


Recommended Posts

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

 

;#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)

 

Link to post
Share on other sites

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.

Link to post
Share on other sites
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

 

Link to post
Share on other sites

Open notepad and run it, you will see the result...Make sure you activate the notepad windows before ;)

Edited by Nine
Link to post
Share on other sites
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 by ITO
Link to post
Share on other sites

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... 

Link to post
Share on other sites
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... 

;#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

 

Link to post
Share on other sites

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 by Nine
Link to post
Share on other sites
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)

#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}")

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
#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

 

Link to post
Share on other sites
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 by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...