• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1017
  • Last Modified:

Change keyboard layout

Hi,
  I'm looking for a vbs script that can change the keyboard layout on a given computer ( running Windows 2000 / XP ). The problem we're experiencing is for some reason when some users log on, they get the US keymap instead of the UK keymap. This means that they can't get several crucial characters and end up complaining. So, does anyone have a vb script that I could get them to run on login that would automatically set the right keyboard? The users do have permission to change keyboard but not the know how.

Hope you guys can help!
0
petepalmer
Asked:
petepalmer
  • 5
  • 5
  • 5
  • +3
1 Solution
 
jimbobmcgeeCommented:
Have you tried
    SetLocale 2057    '2057 being the UK code

or
    SetLocale en-gb
0
 
petepalmerAuthor Commented:
tried that - doesn't seem to do anything I'm afraid
0
 
Jaime OlivaresSoftware ArchitectCommented:
You can use WinAPI functio LoadKeyboardLayout:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput
/keyboardinputreference/keyboardinputfunctions/loadkeyboardlayout.asp

Also take a look to this article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;139571
To implement in Visual basic, take a look to:
http://www.mentalis.org/apilist/LoadKeyboardLayout.shtml

Good luck,
Jaime.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Jaime OlivaresSoftware ArchitectCommented:
Notice that changing Windows Registry directly, you will not have an inmediat effect. But still will be useful to "scan" registry to know installed keyboard layouts, as pointed out in MSDN article I've posted.
0
 
jimbobmcgeeCommented:
Out of interest, Jaime, how do you declare that function from within a VBS?

I tried

   Declare Function LoadKeyboardLayout Lib "user32.dll" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal flags As Long) As Long

as I would in VB6 and it failed with a syntax error...
0
 
Jaime OlivaresSoftware ArchitectCommented:
try to remove the alias (Alias "LoadKeyboardLayoutA")
0
 
MattiCommented:
Hi!

This is module level code:

Public Userkeyboard As String
Public Declare Function LoadKeyboardLayout Lib "user32" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal Flags As Long) As Long
Public Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" (ByVal pwszKLID As String) As Long
Public Const KLF_ACTIVATE = &H1


Public Sub Askkeyboard()
On Error Resume Next
Dim X&, pwszKLI2 As String * 8
X = GetKeyboardLayoutName(pwszKLI2)
Userkeyboard = pwszKLI2
End Sub

Public Sub Restorekeyboard()
Call LoadKeyboardLayout(Userkeyboard, KLF_ACTIVATE)
End Sub

Public Function ChKeyboard(langnum As Long) As Long
On Error Resume Next
Dim X&, setKB As String
DoEvents
Select Case asettelu
Case 0
setKB = "00000419"
Case 1
setKB = "00010419"
Case 2
setKB = "00000423"
Case Else
setKB = "00000419"
End Select
DoEvents
Call LoadKeyboardLayout(setKB, KLF_ACTIVATE)
End Function

Test code on form:
Private Sub Form_Load()
Askkeyboard
Call ChKeyboard(2)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Restorekeyboard
End Sub

More layouts and their constant values you will found from registry
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Nls\LocaleMapIDs
Install more keyboards from windows CD.


Matti

0
 
petepalmerAuthor Commented:
Well I'm looking for some code that I can run as is to set the keyboard to gb :)
0
 
jimbobmcgeeCommented:
Jaime/Matti

Declare Function LoadKeyboardLayout Lib "user32.dll" (ByVal pwszKLID As String, ByVal flags As Long)

returns a syntax error at char 9, when used in a VBS; which looks like it doesn't like the word 'Function'.

How do you call from the API, in a VBS?
0
 
MattiCommented:
Hi, jimbobmcgee!

It's important that this pwszKLID string is fixed lenght 8 char long, won't work if it's not. I don't use VBS on this macine so can't test, but think there is a bug on this API function.

Matti
0
 
Jaime OlivaresSoftware ArchitectCommented:
I think there is no problem with pwszKLID, but, since you are declaring a function you must declare return type:
Declare Function LoadKeyboardLayout Lib "user32.dll" (ByVal pwszKLID As String, ByVal flags As Long) as Long
0
 
petepalmerAuthor Commented:
This is all very interesting but I'm not sure how it solves my problem :)

For the 500 points I either need a working VB script or a compiled VB application - as I don't have Visual Studio to compile it myself.

Thanks in advance!
0
 
jimbobmcgeeCommented:
> I think there is no problem with pwszKLID, but, since you are declaring a function you must declare return type:
> Declare Function LoadKeyboardLayout Lib "user32.dll" (ByVal pwszKLID As String, ByVal flags As Long) as Long

Still it returns a syntax error at char 9 (starting at function)

> This is all very interesting but I'm not sure how it solves my problem :)

If you cannot 'declare' the LoadKeyboardLayout API, you can't use the above code in VBS.  If you want an EXE, send an email to whoever you prefer; I'm sure the listed code will work...

:)
0
 
Jaime OlivaresSoftware ArchitectCommented:
Take a look to this article about using WinAPI functions in VBScript. Hope to be useful.
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10115990.html
0
 
petepalmerAuthor Commented:
I was unable to use any of the options to do what I wanted therefore I'm going to request a refund.
0
 
petepalmerAuthor Commented:
Looking back through the posts, whilst the information might be perfectly acceptable, I was unable to use it to create a script or program that would allow users to set their own keyboard. If someone can provide the information in a script or program form that works, I'll happily accept it - but as it stands I'm not able to use the information I'm afraid.
0
 
jimbobmcgeeCommented:
As mentioned, if you want an executable, send someone here an email (like me) and we'll compile for you, using one of the solutions you choose above...

J.
0
 
moduloCommented:
PAQed with points refunded (500)

modulo
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 5
  • 5
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now