Publius
(Lurker)
2007-03-19 10:56 PM
SendKeys for Shift not working

we are calling SendKeys("^+{END}" to select from the cursor to end of file and the cursor goes to end of file without selecting (Behaves as pressing CTRL+END)
When we use SendKeys("+{END}" the cursor goes to the end of line without selecting (Behaves as pressing END)

Any help is appreciated


Witto
(MM club member)
2007-03-19 11:57 PM
Re: SendKeys for Shift not working

Indeed, no selection is made.
What is your goal? Maybe there are other ways to help you?


AllenAdministrator
(KiX Supporter)
2007-03-20 02:45 AM
Re: SendKeys for Shift not working

Looks like this has been around a while... verified on @kix 4.22 and 4.53
shift + end doesnt work
shift + home doesn't work either.

Ctrl + Shift + Esc does work.

Smells like a bug.


Witto
(MM club member)
2007-03-20 07:26 AM
Re: SendKeys for Shift not working

Maybe a bug.
But maybe Publius could tell what he wants so we can think of a workaround?


Publius
(Lurker)
2007-03-20 02:17 PM
Re: SendKeys for Shift not working

I have a word document that has the first part in english and second half is french , and where the french start I have a text "FRENCH STARTS HERE".

So I want to search for the text and then select the text to the end to create a new file with the french text ,and select the top part to create a english doc.

What I am doing now is search for the text and then I want to do Ctrl+Shift+End to select everything to the end of file and copy to clipbooard.


Thank you all for the help


Gargoyle
(MM club member)
2007-03-20 05:00 PM
Re: SendKeys for Shift not working

You might try making two array's

 Code:
$Text = ReadLine(1)
$Counter = 0
DO 
  ReDim Preserve $Array1[$Counter]
  $Array1[$counter] = $Text
  $Text = Readline(1)
  $Counter = $Counter + 1
Until $Text = "FRENCH STARTS HERE"

$Text = ReadLine(1)
$Counter = 0
Do
  ReDim Preserve $Array2[$Counter]
  $Array2[$Counter] = $Text
  $Counter = $Counter + 1
  $Text = Readline(1)
Until @Error = 0



BillBarnard
(Starting to like KiXtart)
2007-03-20 05:01 PM
Re: SendKeys for Shift not working

The following code works for me:-

break on

Run "C:\Windows\Notepad"

Sleep 3

If SetFocus("Untitled - Notepad") <> 0

"Error SetFocus to Notepad" ?
Exit 2

Endif

$ = SendKeys("The cat sat on the mat{ENTER}")
$ = SendKeys("{UP}")
$ = SendKeys("+{END}")


Witto
(MM club member)
2007-03-20 06:41 PM
Re: SendKeys for Shift not working

Dear BillBarnard,
I tried your code with kix32.exe v4.53 and nothing was selected. Could you tell wich executable and version you are using?

Dear Publius,
IIWY, I would try COM scripting and work with a Word object.
I have too less time to try something.
Part of the code I would write, I would try to get from the macro wizard in Word.


Publius
(Lurker)
2007-03-20 09:25 PM
Re: SendKeys for Shift not working

Thank you all for all your help
I will use a combination of the code from Gargoyle and the suggestion from Witto.

Thank you again


Witto
(MM club member)
2007-03-21 12:02 AM
Re: SendKeys for Shift not working

Oh well
Something to get you started
;*************************************************************************
; Script Name:
; Author: Publius
; Date: 20/03/2007
; Description: Find "FRENCH STARTS HERE"
;************************************************************************* 


;Script Opions
If
NOT @LOGONMODE
    Break On
Else
    Break Off
EndIf
Dim $RC
$RC = SetOption("Explicit", "On")
$RC = SetOption("NoMacrosInStrings", "On")
$RC = SetOption("NoVarsInStrings", "On")
$RC = SetOption("WrapAtEOL", "On")

;Declare variables
Dim
$objWord
, $strWordFile, $strFind
$strWordFile = "\\Server\Share\Deeper\YourFile.doc"
$strFind = "FRENCH STARTS HERE"

;Create Word object
$objWord
= CreateObject("Word.Application")
If @ERROR
    ? "Error creating Word object"
    ? "Error " + @ERROR + ": " + @SERROR
    Quit @ERROR
EndIf

;Open Word document
;Maybe you can do everything invisible and comment the next line

$objWord.Visible = 1
$RC = $objWord.Documents.Open($strWordFile)
$objWord.Selection.Find.Text = $strFind
$RC = $objWord.Selection.Find.Execute

; Other stuff
; Complete your script


;Do not forget to close word if working invisible
$RC
=
$objWord.Application.Quit

The File/Open and the Find are easy to recreate if you just play a while with your macro recorder in Word. Just give it a try.


Witto
(MM club member)
2007-03-21 01:13 AM
Re: SendKeys for Shift not working

About the select that is not working with SendKeys.
Can this be considered as a bug or as a hidden feature? Wouldn't it be better to see it more work as expected? Should it be posted in the Beta forum?


Richard H.Administrator
(KiX Supporter)
2007-03-21 11:26 AM
Re: SendKeys for Shift not working

I'm not sure that this is a bug. From a quick test I just did, there is no "Shifted" equivalent of the Insert/Delete/Home/End/Page Up/Page Down keys. Holding Ctrl+End does generate a different code.

If this is the case then you cannot possibly send a Shift-End key combination.

My guess is that the application receives an "End" key, then checks the state of the keyboard to see if the shift key is being pressed *at the same time*. You cannot emulate this by using SendKeys(), which is just forcing keypresses into the keyboard buffer.

You might get around this with a tool like AutoIT which has a "{SHIFTDOWN}", but even with this you would probably need to wait until the application is ready, send the shift-down, send the "End" key and wait for it to be actioned. Then you can send the shift-up.


Benny69
(MM club member)
2007-03-21 02:26 PM
Re: SendKeys for Shift not working

Richard prolly just forgot about this but there is a solution with KiX, all you have to do is turn the numlock off and the shift+end ("+{END}) will work.
in this example i am using Word to determain if the numlock is on:
 Code:
$WordShell = CreateObject("Word.Application")
$NumLock = $WordShell.NumLock

Run "notepad.exe"

$ = SetFocus("Untitled - Notepad")
Sleep 1
$Key = SendKeys("abcdefg")
Sleep 1
$Key = SendKeys("{ENTER}")
Sleep 1
$Key = SendKeys("{UP}")
Sleep 1

If $NumLock = -1
	$Key = SendKeys("{NUMLOCK}")
	Sleep 1
	$Key = SendKeys("+{END}")
	Sleep 1
	$Key = SendKeys("{NUMLOCK}")
	Sleep 1
Else
	$Key = SendKeys("+{END}")
	Sleep 1
EndIf


Witto
(MM club member)
2007-03-21 05:20 PM
Re: SendKeys for Shift not working

Whow, a NumLock bug.
Anyway, I would rely more on COM scripting, because the line
 Code:
$ = SetFocus("Untitled - Notepad")
is depending on the language of the operating system


Benny69
(MM club member)
2007-03-21 05:21 PM
Re: SendKeys for Shift not working

well that was just as an example to show that it works if the numlock is off.


AllenAdministrator
(KiX Supporter)
2007-03-21 06:19 PM
Re: SendKeys for Shift not working

Numlock on or off!!! Nice find. How in the world did you figure that out?

Benny69
(MM club member)
2007-03-21 07:32 PM
Re: SendKeys for Shift not working

My Kung-Fu is strong ;\)

AllenAdministrator
(KiX Supporter)
2007-03-21 09:02 PM
Re: SendKeys for Shift not working

ahhh... so that's what you call that smell. ;\)

Benny69
(MM club member)
2007-03-21 11:57 PM
Re: SendKeys for Shift not working

lol