Hemonto

Hi,

I'm working on a project with some biomatrix devices. My one issue is that, i need to change my keyboard layout from English to Bangla and vise versa that should be done by programatically. When one want to give an input what would take english character then keyboard layout will be autometically changed and when one want to give an input what would take bangla character then keyboard layout will be changed autometically. I can do this manually by pressing CTRL + ALT + B keys. But i need to do this by programatically. I'm using C# desktop application.

Could any body help me about this issue.

Thanks in advanced.

HKB




Re: Visual Basic Express Edition Change Keyboard layout

nobugz

Try assigning the InputLanguage.CurrentInputLanguage property. I can't try it, I just have US.





Re: Visual Basic Express Edition Change Keyboard layout

Hemonto

Hi, Basically i need to work on Bangla keyboard layout what is not present in default language settings of control panel's Regional and Language Option. So that i can't use InputLanguage.CurrentInputLanguage property. Here we make a software named Bijoy Bangla keyboard what changes keyboard layout programatically that is not included into Regional and Language Option. In Bijoy software - it is always monitoring which key combination is pressed just now. If it presses, Ctrl+Alt+B then it changes keyboard layout into English and if i press same combination again then it change keyboard layout in Bangla. I hope i'm able to understand the depth technique how my Bijoy software working.

Now my problem is that, Bijoy software in running in my computer by back process. From my one of textbox of my C# project, i need to press Ctrl+Alt+B key combination what will capture by bijoy software and then it change my keyboard layout accordingly.

How can i send this key combination (Ctrl+Alt+B) by SendKeys.SendWait(string keys) method.

please help me by this issue and thanks in advanced.

HKB






Re: Visual Basic Express Edition Change Keyboard layout

nobugz

Okay, sounds like you've got some sort of utility that is monitoring key strokes with SetWindowsHookEx(). The first thing I'd try is to send the keystroke combination with SendKeys.Send(). That is not likely to work though. Your next bet is to synthesize the keystrokes with the SendInput() API function. Google for that function name, you should find plenty of examples.





Re: Visual Basic Express Edition Change Keyboard layout

Hemonto

Thank you for your reply. I have tried by SendKeys.Send() method. but it doesn't work. I need to set keystroke by key combination that will get by windows. Could you please give me an example of SendInput() API Function for key combination (CTRL + Alt+ B). please

HKB






Re: Visual Basic Express Edition Change Keyboard layout

nobugz

Check this thread.





Re: Visual Basic Express Edition Change Keyboard layout

Hemonto

Hi,

Thanks a lot for your help regarding this issue. I have studied your given thread. I tried by passing a key combination (say, Ctrl+Alt+F12) from form's Form2_KeyUp Event

but it happens nothing. Could you please help me about where the error is. Hereby i have submitted by code for your kind consideration. it's very very important to resolve my issue. My project is hang up with this issue. Please help me.

Thanks in advance.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

using System.Runtime.InteropServices.ComTypes;

namespace WindowsApplication2

{

public partial class Form2 : Form

{

private const int WM_KEYDOWN = 0x0100;

private const int WM_SYSKEYDOWN = 0x0104;

protected override void WndProc(ref Message m)

{

base.WndProc(ref m);

}

public Form2()

{

InitializeComponent();

}

//import the dll and use interop marshaling to take the INPUT[] and pass the pointer to the first element, ala C.

[DllImport("user32.dll")]

static extern UInt32 SendInput(UInt32 nInputs, INPUT[] inputs, int cbSize);

//this function would be called from the app to send whatever virtual keycode you wanted. It will need to be modified to allow for key combinations, like <shift>, or <alt>, and such.

internal static void SendMyInput(short[] code)

{

const Int32 INPUT_KEYBOARD = 1;

KEYBDINPUT kbi = new KEYBDINPUT();

INPUT input = new INPUT();

INPUT[] inputs = new INPUT[code.Length];

Int32 size = 0;

for (int i = 0; i < code.Length; i++)

{

kbi.wVk = codeIdea;

input.ki = kbi;

input.type = INPUT_KEYBOARD;

//get the marshalled size of the data structure without the additional bytes of managed information.

size = Marshal.SizeOf(input);

inputsIdea = input;

}

//since the signature contains the marshalling clues, just pass the array.

SendInput(1, inputs, size);

}

//layout the three defined possible parts of the union in sequential order

[StructLayout(LayoutKind.Sequential)]

internal struct KEYBDINPUT

{

internal short wVk;

internal short wScan;

internal Int32 dwFlags;

internal Int32 time;

internal UIntPtr dwExtraInfo;

}

[StructLayout(LayoutKind.Sequential)]

internal struct MOUSEINPUT

{

internal Int32 dx;

internal Int32 dy;

internal Int32 mouseData;

internal Int32 dwFlags;

internal Int32 time;

internal UIntPtr dwExtraInfo;

}

[StructLayout(LayoutKind.Sequential)]

internal struct HARDWAREINPUT

{

internal Int32 uMsg;

internal short wParamL;

internal short wParamH;

}

//use explicit layout to align the union on the correct boundaries

[StructLayout(LayoutKind.Explicit)]

internal struct INPUT

{

[FieldOffset(0)]

internal Int32 type;

[FieldOffset(4)]

internal MOUSEINPUT mi;

[FieldOffset(4)]

internal KEYBDINPUT ki;

[FieldOffset(4)]

internal HARDWAREINPUT hi;

}

private void Form2_KeyUp(object sender, KeyEventArgs e)

{

// Send key for Ctrl + Alt + F12 to display Graphics Controller Properties of any PC

SendMyInput(new short[] { 17, 18, 123 });

}

}

}






Re: Visual Basic Express Edition Change Keyboard layout

nobugz

Don't forget the key up events.





Re: Visual Basic Express Edition Change Keyboard layout

Hemonto

HI,

I'm sorry that i can't understand what you say. Please say me clearly. What i have done right now and that is i send Ctrl+Alt+F12 keys from form's key_up Event.

private void Form2_KeyUp(object sender, KeyEventArgs e)

{

// Send key for Ctrl + Alt + F12 to display Graphics Controller Properties of any PC

SendMyInput(new short[] { 17, 18, 123 });

}

What i need to do now

Or,

If i call SendMyInput(new short[] { 17, 18, 123 }) function with these parameter from click event of a button what i need to do next.

Thanks You,

HKB






Re: Visual Basic Express Edition Change Keyboard layout

nobugz

Check the MSDN docs for KEYBDINPUT and read the description of the dwFlags member. To simulate a key press, you need to generate two events. One for the key going down (dwFlags = 0), another for the key going up (dwFlags = KEYEVENTF_KEYUP).