Page 1 of 1

How can simulate the press of the "HOME" key in a script ?

Posted: 25 Mar 2012 16:34
by Ysl
Hi

I would like to know how can simulate the press of the "HOME" key in a script ?

thanks for your kelp !

Ysl

Re: How can simulate the press of the "HOME" key in a script

Posted: 25 Mar 2012 19:51
by serendipity
Ysl wrote:Hi

I would like to know how can simulate the press of the "HOME" key in a script ?

thanks for your kelp !

Ysl

Code: Select all

//Go home
   #348;

Re: How can simulate the press of the "HOME" key in a script

Posted: 25 Mar 2012 21:04
by eil
i guess he was asking for this:

Code: Select all

sendkeys "{home}";

Re: How can simulate the press of the "HOME" key in a script

Posted: 25 Mar 2012 21:46
by serendipity
eil wrote:i guess he was asking for this:

Code: Select all

sendkeys "{home}";
Oh! thats right. But in this situation context is important. Depends on what the user is trying to achieve. Maybe add focus; before sendkeys if its for list or focus tree; if its for tree.

Re: How can simulate the press of the "HOME" key in a script

Posted: 28 Mar 2012 10:54
by Ysl
Thanks all for your help !
Unfortunately, none works for me...
Let me explain a little bit more.

Code: Select all

End GetInfo("CountSelected") < 1, "No item(s) selected.";
   Global $files;
   $files = Report("{Dir |{FullName};{Ext}<crlf>|}", 1);
   Setting "AllowRecursion", 1;
   Sub "_newTXT";
   $files = RegexReplace($files, "^(.*);.*<crlf>", "$1|");
   Delete 1,0,$files;
   
"_newTXT"
   Global $files, $i;
   $i = $i Like "" ? 1 : $i;
   $token = GetToken($files, $i, "<crlf>");
   End $token Like "",, 1;
   $file = GetToken($token, 1, ";");
   $ext = GetToken($token, 2, ";");
   $newFile = RegexReplace($file, "$ext$", "txt");
   New $newFile;
   $i = $i + 1;
   Sub "_newTXT";
   moveto "F:\Dummy Files", $newFile;
This script (thanks to the forum helpers!)0, applied to a file, create a new file with same name with new .txt extension, move it to the Dummy folder then delete the original file.

But at the end of the script, the "selection" is at the bottom of the list (file are sorted by created date) and I always have to push the HOME key to go back to where I was (at the top of the list/window). So I would like to do this automatically...

BTW there is an active Visual filter which show only music files. And with the #348; command, the list is at the top of the list BUT Visual filter is cancelled and date sorting also (now the list is sorted alphabetically) and more columns are created (ATTR/LEN/TAGS/COMMENTS etc)...
EDIT: with "sendkeys "{HOME}";" (HOME is now Uppercase), I get the same result as the #348; command

That's strange because if I press the Home key I should get the same result as the sendkeys "{HOME}"; ????

I hope it's more clear to understand my problem and sorry for my bad english

Re: How can simulate the press of the "HOME" key in a script

Posted: 28 Mar 2012 11:24
by highend
It doesn't matter which file / folder is selected after you've run the script?

Just add a

Code: Select all

sel 1;
to your code...

At least it serves your purpose :D

Re: How can simulate the press of the "HOME" key in a script

Posted: 28 Mar 2012 13:11
by Ysl
"sel 1;"

GREAT ! Exactly what I was lookig for !

Does this script SELECT line 1 ?

thanks !

Re: How can simulate the press of the "HOME" key in a script

Posted: 28 Mar 2012 13:35
by highend
Does this script SELECT line 1 ?
Exactly.

Re: How can simulate the press of the "HOME" key in a script

Posted: 28 Mar 2012 13:54
by Ysl
Ok ! but this make me think it would be even better that the line number selected at the end of the script (line 1 for now) would be the same as the one of the .mp3 file I selected at the beginning of the script..

So is it possible to save the original line number as a variable and at the end of the script input the variable value to get back to the original line selected ?

So if I'm on line 6 when I call the script, at the end I would be back on line 6

That would be even greater !!

Thanks

Re: How can simulate the press of the "HOME" key in a script

Posted: 28 Mar 2012 14:07
by highend
This will always select the first file from your original selection, when the script has finished
it's job.

Code: Select all

End GetInfo("CountSelected") < 1, "No item(s) selected.";
   Global $files, $select;
   $files = Report("{Dir |{FullName};{Ext}<crlf>|}", 1);
   $select = gettoken($files, 1, ";");
   Setting "AllowRecursion", 1;
   Sub "_newTXT";
   $files = RegexReplace($files, "^(.*);.*<crlf>", "$1|");
   Delete 1,0,$files;
   
"_newTXT"
   Global $files, $select, $i;
   $i = $i Like "" ? 1 : $i;
   $token = GetToken($files, $i, "<crlf>");
   End $token Like "",, 1;
   $file = GetToken($token, 1, ";");
   $ext = GetToken($token, 2, ";");
   $newFile = RegexReplace($file, "$ext$", "txt");
   New $newFile;
   $i = $i + 1;
   Sub "_newTXT";
   moveto "F:\Dummy Files", $newFile;
   sel "[$select]", , 1;

Re: How can simulate the press of the "HOME" key in a script

Posted: 28 Mar 2012 14:25
by Ysl
thanks but this script showed me 2 errors

Image

Image

Re: How can simulate the press of the "HOME" key in a script

Posted: 28 Mar 2012 15:15
by highend

Code: Select all

"_newTXT"Global $files, $select, $i;
The Global... part must be on the next line.

But it doesn't matter anyway. All of your files are deleted / moved so it makes no sense to save the first file and try to select it afterwards. Time for a different solution.

Re: How can simulate the press of the "HOME" key in a script

Posted: 28 Mar 2012 15:53
by Ysl
Sorry but this is beyond my comprehension....