Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change keyboard layout

Status
Not open for further replies.

RHill

Programmer
Sep 18, 2001
3
CA
I am working on an app that requires input in English and French. I have installed the English US and Canadian French keyboards and can switch between them manually with Left Alt+Shift. Does anyone know how to do this with VB. I have loaded the Microsoft Visual Keyboard and attempted to change the language using SendKeys but it does not recognize Left Alt+Shift.

I have used SendKeys "%+" and SendKeys "%(+)". Neither work. As a test I used SendKeys "{CAPSLOCK}" and the Visual Keyboard accepted this.

I have also tried changing the language using Ctrl+Shift. Again this works manually but not programmatically.

Any ideas?

RHill
 
Give this a try.

Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
'-----------------------------------------------------------------------------------------------------------------------
'Note: The Following Constants Represent the Left Keyboard Key Constants that are Used, Adjust/Add as Needed
'-----------------------------------------------------------------------------------------------------------------------
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_LMENU = &HA4
Private Const VK_LSHIFT = &HA0

Private Sub Command1_Click()
keybd_event VK_LMENU, 0, 0, 0
keybd_event VK_LSHIFT, 0, 0, 0
keybd_event VK_LMENU, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_LSHIFT, 0, KEYEVENTF_KEYUP, 0
DoEvents
End Sub

Let me know if it works. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top