set/p with time?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Re: set/p with time?

#31 Post by tcpman » 05 Sep 2014 14:14

@agerman
tnx but i could not understand what your script do! sory i am not pro in batch can you add some notes about it?




pepen

what about using vbs file to do the shift + alt job?

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

Re: set/p with time?

#32 Post by penpen » 05 Sep 2014 14:16

@aGerman: Doesn't this just loads some installed but not loaded keyboard layouts?
(Sorry: I can't test this... on Win XP this doesn't work.)

If it sets the default keyboard layout to the specified, then this is really nice.
But you should always keep in mind to reset to the original value after the batch script.

If you test the above this "keyBoardLayoutDemo.cs" may help:

Code: Select all

using System;
using System.Windows.Forms;

public class Test {
   public static void displayLanguages () {
      // Gets the list of installed languages.
      int i=0;
      Console.WriteLine("Default input language: {0}", InputLanguage.DefaultInputLanguage.Culture.EnglishName);
      Console.WriteLine("Current input language: {0}", InputLanguage.CurrentInputLanguage.Culture.EnglishName);
      Console.WriteLine();
      Console.WriteLine("Installed languages:");
      foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages) {
         i+=1;
         Console.WriteLine("{0}: \"{1}\"", i, lang.Culture.EnglishName);
      }
   }

   public static InputLanguage GetInputLanguageByName(string inputName) {
      foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages) {
         if (lang.Culture.EnglishName.Equals(inputName)) {
            return lang;
         }
      }

      return null;
   }

   static void Main (string [] args) {
      if (args.Length == 0) {
         displayLanguages ();
      } else if (args.Length == 2 & args [0].Equals ("/runCmd")) {
         string langString = args [1];
         InputLanguage lang = GetInputLanguageByName (langString);

         if (lang != null) {
            InputLanguage.CurrentInputLanguage = lang;
            System.Diagnostics.Process.Start ("CMD.exe", "");

            displayLanguages ();
         } else {
            Console.WriteLine("Error Could not set the keyboard layout to \"{0}\".", langString);
            Console.WriteLine("Maybe not installed or loaded.");
            Console.WriteLine();
            Console.WriteLine("Actual settings:");
            displayLanguages ();
         }
         
      } else {
         Console.WriteLine("Usage: keyboardLayout[.exe] [/runCmd name]");
         Console.WriteLine("  name  the english name of keyboard layout that should be set.");
         Console.WriteLine("        Only succeeds if the keyboard layout is installed and loaded.");
         Console.WriteLine();
         Console.WriteLine("If using '/runCmd \"name\"', then this program starts another cmd thread using");
         Console.WriteLine("the specified kexboard layout, else this program displays some status info:");
         Console.WriteLine("- The english name of the default keyboard layout,");
         Console.WriteLine("- the english name of the current keyboard layout, and");
         Console.WriteLine("- the english name of the all loaded keyboard layouts.");
         Console.WriteLine();
         Console.WriteLine();
      }
   }
}

You could compile it using this "csc.bat":

Code: Select all

// // >nul 2> nul & @goto :main
/*
:main
   @echo off
   setlocal
   cls

   set "csc="

   pushd "%SystemRoot%\Microsoft.NET\Framework"
   for /f "tokens=* delims=" %%i in ('dir /b /o:n "v*"') do (
      dir /a-d /b "%%~fi\csc.exe" >nul 2>&1 && set "csc="%%~fi\csc.exe""
   )
   popd

   if defined csc (
      echo most recent C#.NET compiler located in:
      echo %csc%.
   ) else (
      echo C#.NET compiler not found.
      goto :eof
   )

rem   %csc% /nologo /optimize /warnaserror /nostdlib /nowin32manifest /debug- /target:exe /out:"%~f1.exe" "%~f1.cs"
   %csc% /nologo /warnaserror /r:System.dll /r:System.Windows.Forms.dll /r:System.Drawing.dll /target:exe /out:"%~f1.exe" "%~f1.cs"
rem   %csc% /nologo /warnaserror /target:exe /out:"%~f1.exe" "%~f1.cs"
rem   %csc% /?
   goto :eof
*/
Note: ".NET" framework has to be installed: Should be the default since Windows Vista.

The compile command is this:

Code: Select all

Z:\>csc "keyBoardLayoutDemo"

penpen

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

Re: set/p with time?

#33 Post by penpen » 05 Sep 2014 14:34

tcpman wrote:what about using vbs file to do the shift + alt job?
I'm not sure, i don't believe it: But it might work if you use the vbs/js to create a child process and then send SHIFT+ALT to it... .
But you have to execute this vbs for every single call to any external tool,
this would be an enormous overhead and would slow down any script.
In addition, when using choice it could send 2 wrong inputs to it, if the send keys are not treated as speciatl keys (2 x beep).
The SHIFT+ALT also has to reach the tool (-> choice, ...) earlier than any other user input (may fail on redirected input).

penpen

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

Re: set/p with time?

#34 Post by aGerman » 05 Sep 2014 14:37

tnx but i could not understand what your script do

It should change the keyboard layout to English - United States (0409, see the linked list). Just call the subroutine with the LCID you want.

Doesn't this just loads some installed but not loaded keyboard layouts?

Yes it does.

Code: Select all

I can't test this... on Win XP this doesn't work.

I'm surprized. I could have sworn that it worked under XP. It doesn't change the keyboard layout for the already running script. You have to run another application or script e.g.

Code: Select all

start /wait cmd /c "whatever.bat"


If it sets the default keyboard layout to the specified, then this is really nice.
But you should always keep in mind to reset to the original value after the batch script.

True. But since we still don't know where tpcman is from i wasn't able to implement it.

If you test the above this "keyBoardLayoutDemo.cs" may help

That's cool stuff :)

Regards
aGerman

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

Re: set/p with time?

#35 Post by tcpman » 09 Sep 2014 01:46

thanks guys you helped me a lot :D

Post Reply