set/p with time?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: set/p with time?

#16 Post by Squashman » 04 Sep 2014 16:35

After doing some reading the codepage shouldn't make a difference for those ascii characters. It does sound like it is a keyboard language problem. I saw something like this happen a few years ago. The user had changed their keyboard language and then none of their scripts or shortcuts worked.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: set/p with time?

#17 Post by Squashman » 04 Sep 2014 16:42

Antonio, I certainly can't disagree with your point of view. I try to code things the simplest way possible. This should be a rudimentary task with the choice command. I like your programs for their unique abilities to overcome batch deficiencies but I just think it is overkill in this instance. If this is a keyboard language problem I would think your program would not work either because they may be pressing the physical W key but the language setting is sending a different character.

tcpman
Posts: 53
Joined: 05 Mar 2014 15:01

Re: set/p with time?

#18 Post by tcpman » 05 Sep 2014 02:05

changed the chcp code still does not work!


i do some tests looks like the choice command does not care about the language of keys i send its only need to press shft + alt
even when my language is english and then i open script still give me beep sound by pressing wasd but after shift + alt when even language is not english its works!

also the focus must be on the command prompet window for example if i press shif + alt when the focus in on notepad it wont work!

very strange!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: set/p with time?

#19 Post by foxidrive » 05 Sep 2014 02:35

tcpman wrote:also the focus must be on the command prompet window for example if i press shif + alt when the focus in on notepad it wont work!


This is one of the most basic concepts of Windows - the foreground window and all background windows.

Only one window has focus.

tcpman
Posts: 53
Joined: 05 Mar 2014 15:01

Re: set/p with time?

#20 Post by tcpman » 05 Sep 2014 09:35

yes

but what to do?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: set/p with time?

#21 Post by foxidrive » 05 Sep 2014 09:53

tcpman wrote:the problem is choice command has some problems for me!


What version of Windows are you using?

Are you using the native choice.exe or an addon replacement?

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: set/p with time?

#22 Post by penpen » 05 Sep 2014 10:00

tcpman wrote:i do some tests looks like the choice command does not care about the language of keys i send its only need to press shft + alt
even when my language is english and then i open script still give me beep sound by pressing wasd but after shift + alt when even language is not english its works!
I'm not sure about your actual situation (confusing, that you said ".. even language is not english");
i think the following is true:
Your default keyboard layout is "A (B)" (for example "German (Germany)".
Then you have switched your current keyboard layout from "A (B)" to "English (...)"
After that you start the batch script: But "set/P" only works after pressing SHIFT+ALT.

If the above is your situation, then the cause of that issue is:
Child processes/threads will be created using the default keyboard layout.
So if you start the batch script, a child (process/thread) is created with the default keyboard layout (== not "English (...)"), so you have to press SHIFT+ALT.
Sad to say that windows actually doesn't support to change this for child/parent processes using actual programming languages.

If you don't want to press SHIFT+ALT (again and again) then the only workaround (i know) is,
to set the default keyboard layout to "English (...)", while working on your batch.
With this setting a newly created batch process/thread is using the "English (...)" keyboard layout.
After you have finshed your (batch) work, you should reset the default layout back to "A (B)" to avoid other problems.

penpen

tcpman
Posts: 53
Joined: 05 Mar 2014 15:01

Re: set/p with time?

#23 Post by tcpman » 05 Sep 2014 10:09

@foxdrive
win 7 no i use choice.exe



@penpen

look

my keybord language is en i start batch need's shif + alt
my keybord language is not en i start batch and still need's shft + alt

so i think the choice does not care about my language at all its just need me to press shft + alt
even when language is english and i run script still need shft + alt and the imteresting thing is when i press it its works! but the language is not english because when i type into notepad or something is not english anymore because i pressed shift + alt but its work in the batch script

my problem is with choice other commands are oky

can someone upload his own choice.exe for me so i can test it?

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: set/p with time?

#24 Post by einstein1969 » 05 Sep 2014 10:14

tcpman wrote:hi all

i am creating a game and i was wondring
is it possible to use a timer with set/p
so if the timer equal to 0
and no input has been giving we go to a label or something?

i think its inpossible because of batch interpreter runs the line one by one!

but just wanted to ask!


I think it's possible using multithreading batch.

1) start a thread with input. (sign the pid)
2) start a second thread that count and kill the first thread

OR you can use alternate input method with xcopy http://www.dostips.com/forum/viewtopic.php?p=33741#p33741

a trace

Code: Select all

@echo off & if NOT "%1"=="" goto :%1

del %tmp%\input.save.dat.txt 2>nul

start "" /B cmd /c "%0 setp"

ping 127.0.0.1 -n 8 >nul

if not exist %tmp%\input.save.dat.txt  goto :Timeout

type %tmp%\input.save.dat.txt

exit /b

:Timeout
echo No input detect
rem kill the process...
exit /b


:setp

setlocal EnableDelayedExpansion

set /p "v=" <CON:

>%tmp%\input.save.dat.txt echo !v!

exit /b




einstein1969

tcpman
Posts: 53
Joined: 05 Mar 2014 15:01

Re: set/p with time?

#25 Post by tcpman » 05 Sep 2014 11:55

@einstein1969


tnx i will give it a try

----------------
also i was thinking maybe we could do what shift+alt do in batch? so then the problem will be solved

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: set/p with time?

#26 Post by ShadowThief » 05 Sep 2014 12:54

tcpman wrote:even when language is english and i run script still need shft + alt and the interesting thing is when i press it its works! but the language is not english because when i type into notepad or something is not english anymore because i pressed shift + alt but its work in the batch script

It sounds like your default language isn't English, which is why when you changed your keyboard language to English and then started the script, the keyboard was set back to whatever the default is for you.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: set/p with time?

#27 Post by penpen » 05 Sep 2014 13:00

@ShadowThief
I fully agree with you :D .

@tcpman
I think you have not fully realized what i've written in my above post.
I'm pretty sure your default keyboard layout is NOT "English (...)".
Because i don't know your default keyboard layout, i will denote it with "Your".

This may happen in your described cases (if i am right):
tcpman wrote:my keybord language is en i start batch need's shif + alt
my keybord language is not en i start batch and still need's shft + alt
(...)
even when language is english and i run script still need shft + alt and the imteresting thing is when i press it its works!
It doesn't matter if you have set the keyboard layout to a specific value (en/not en):
This value will be ignored, whenever a new process/thread is created.
So whenever your batch reaches the line with choice and wants to execute it,
the system creates a new process/thread with the default keyboard layout "Your".
The same happens to all external tools (executable files).

tcpman wrote:but the language is not english because when i type into notepad or something is not english anymore because i pressed shift + alt but its work in the batch script
You may set current keyboard layout of the process/thread, that executes notepad to whatever value you like.
It has to do nothing with the current keyboard layout value of your command shell.
And this value of the command shell has nothing to do with the current keyboard
layout of the external choice command.
Every process has its own current keyboard layout value.


tcpman wrote:so i think the choice does not care about my language at all its just need me to press shft + alt
And i've probably described the reason above.

tcpman wrote:my problem is with choice other commands are oky
I asusme you have tested for example "set /P".
There this issue doesn't occure, because it is an internal command.
Internal commands are executed within the current "cmd.exe" thread/process.
So they don't use their own keyboard layout.

penpen

tcpman
Posts: 53
Joined: 05 Mar 2014 15:01

Re: set/p with time?

#28 Post by tcpman » 05 Sep 2014 13:21

oh yes sory my mistake

tnx all the problem is now solved

but what about others?? is there any way to change the default language with batch? or do the shft+alt work?
because i going to give this to others

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: set/p with time?

#29 Post by penpen » 05 Sep 2014 13:47

oh yes sory my mistake
No problem.

As written above, i'm sad to say that windows actually doesn't support the change of the keyboard layout for child/parent processes/threads programatically.
As far as i know it even can't be done using any programming language.
Even when using hooks it is just a temporary success... :
- while "hooking", it could be changed, but
- if the "hooking" process terminates the unchanged values are in use again.
Beside this, such applications are detected by nearly any virus scanner... .

penpen

Edit: Added some text to be more clear.
Last edited by penpen on 05 Sep 2014 14:06, edited 1 time in total.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: set/p with time?

#30 Post by aGerman » 05 Sep 2014 13:53

Maybe it is possible to specify the keyboard layout programmatically.

Code: Select all

@echo off &setlocal
call :changeKL 0409
:: your code
goto :eof


:changeKL LCID
>"%temp%\config.xml" (
  echo ^<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend"^>
  echo   ^<gs:UserList^>
  echo     ^<gs:User UserID="Current"/^>
  echo   ^</gs:UserList^>
  echo   ^<gs:InputPreferences^>
  echo     ^<gs:InputLanguageID Action="add" ID="%1:0000%1" Default="true"/^>
  echo   ^</gs:InputPreferences^>
  echo ^</gs:GlobalizationServices^>
)
control intl.cpl,, /f:"%temp%\config.xml"
del "%temp%\config.xml"
goto :eof

Have a look at the list os LCIDs.
The behavior may differ though. MS changed it for Win8 as far as I read there.

Regards
aGerman

Post Reply