how to know a input is ime or tsf? - text-services-framework

i use win7 64bit, local language is chinese.
some input use ime, and some input use tsf.
i want use LoadKeyboardLayout() to active a special keyboard layout sometimes, but when call GetKeyboardLayoutName(), the tsf input and default ime return same keyboard layout "0x00000804"。
so i can't active tsf input use LoadKeyboardLayout(), i know how to active tsf input through ITfInputProcessorProfiles interface.
but how to get current input is ime or tsf?
thanks.

When the language changes, TSF will send notifications via ITfLanguageProfileNotifySink, when the IME changes, TSF will send notifications via ItfActiveLanguageProfileNotifySink.

Related

What's the MacOS API to "capture" the mouse and keyboard, the way a VM or remote desktop program would do?

I'm looking for the Mac OS API that virtual machine or remote desktop type programs would use to "capture" the mouse and keyboard. That is to say, I want to write a GUI program where when the user clicks in my window, the normal mouse cursor disappears, and all keyboard and mouse input is diverted to my program, including global shortcuts like cmd-tab. What's the name of this API?
Found it: CGEventTapCreate can tap into the low level event stream to receive, filter, or insert HID events.

Reading from a USB HID device that behaves like a keyboard

I am trying to read the input from a barcode scanner that behaves like a keyboard using the hidapi (https://github.com/signal11/hidapi). Apparently the OS does not allow me to access the scanner because it behaves like a keyboard and for security reasons the OS owns all the keyboard and mice devices. The manufacturer of this barcode scanner does not provide any drivers. Is there a way to prevent the OS from owning this barcode scanner or maybe a way to turn it into a serial port and read from it?
In case there is no workaround for this, does anyone know a cheap barcode scanner that does not behave like a keyboard so that I can use the hidapi to access it? Or how can I know that a barcode will not behave like a keyboard? It is a very specific question that most sellers don't know how to reply.
Thanks.
A device that only simulates keyboard input, such as a barcode scanner, does not have a way to control programmatically, rather than an interactive device such as a game controller.
You just wait for the barcode data to be notified as keyboard input data.
It will notify you even if you do not own the device. In other words, you need to own keyboard focus. It is ordinary Windows programming knowledge.
Many keyboard input barcode scanners have the ability to customize prefix / suffix codes that are appended to the front and back to identify barcode data input.
They can be customized by reading the settings barcode.
Check the notified key code one by one in the application program, and if such special data comes, please treat it as barcode data.
By "OS" do you mean Windows? Other operating systems usually provide a means to intercept keystrokes. Linux, for example, has the input subsystem which lets you intercept keyboard events like keys being pressed and released. Unfortunately, these leave it to you to convert to ASCII/UTF-8 characters yourself.
An easier option, regardless of OS, may be to look for a barcode scanner that emulates a USB-Serial device. That would appear to the system as COMx in Windows, /dev/ttyUSBx in Linux, etc. Then you can just read the data from it using a serial port library and not worry about keyboard focus.

How can I know hooked keyboard ID?

I have two keyboards connected on my computer. I want to use one for the main keyboard, and another for a specific application. For example, keyboard #1 is used for Windows, and keyboard #2 is used only in my application.
Is it possible? If yes, which language should I use? Do I need to access to the driver? I precise that I'm running under Windows...
I found a link that explain step by step how to intercept keyboard keys, and how to identify the device that sent the keystroke.
Using Raw Input from C# to handle multiple keyboards
This example uses C# language.

How to send the output of a software to a Microsoft Windows Virtual Keyboard?

I am using xvkdb with X11 to send the content of my Barcode reader to the Keyboard Focus Window.
But I am looking to port this Barcode Reader on Microsoft Windows. How would you do that?
Here is the bash script :
zbarstream /dev/video | xvkbd -file -
If you just want to copy text, use the clipboard. There are many command line utilities that allow you to copy text to the clipboard. I use my own, very simple 5-lines Delphi pascal. You can find such a utility in Raymond Chen blog the new old thing http://blogs.msdn.com/oldnewthing/archive/2009/11/10/9919908.aspx
This method provides an additional safety that is the user must paste the text into the application, but this additional required action may be undesirable. In that case, or if you need more detailed control, then you need some way to inject keystrokes into the keyboard driver. There are some keyboard simulators and keyboard automation utilities. AutoIT and AutoHK are very popular.
AFAIK, the On-Screen Keyboard included in Windows doesn't have a command-line interface and therefore doesn't support input redirection. I'm not sure about other third-party virtual keyboards as I have never used any.
However, there's the SendKeys scripting method that can be used to simulate keyboard input into the active window. So if you launch your Barcode Reader and capture its output from a script (VBScript/JScript), you should be able to use SendKeys to send that output to the active window.

How to determine the keyboard layout for another process (Windows)?

I'm working on a program that needs to record and play back keystrokes. The main process runs as a service, so it needs a configuration program to record the keystrokes.
The problem comes when the system default keyboard layout is (say) English, and the user's keyboard layout of the moment is (say) German. The user enters a 'ü' character into the configuration interface, which is duly recorded and stored.
Now the user runs Notepad and tries to play the keystroke back, which is done by a child of the service. When transforming input to pass to SendInput, we call VkKeyScan, which then tells us there's no way to reproduce that character on this keyboard (remember the default keyboard layout is English).
What I'd really like to do is sync the keyboard layouts of the service and the current foreground application, so the service can reproduce any character the user can with their keyboard. GetKeyboardLayout only works in the current process. This has to run on both 32- and 64-bit, so a message hook is... not preferred :).
To retrieve the keyboard layout for the foreground window:
GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), NULL))
It sounds like you're recording characters instead of keystrokes. Instead of sending keystrokes when replaying, can you use SendMessage to send WM_CHAR messages with the recorded characters instead of generating keystrokes?

Resources