Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2008.01.27;
Скачать: CL | DM;

Вниз

ToUnicode. Как получить символ с учетом выброного языка...   Найти похожие ветки 

 
MInd_f ©   (2007-06-23 19:47) [0]

Есть функция-фильтр...
LRESULT CALLBACK KeyboardProc(
   int code,
   WPARAM wParam,
   LPARAM lParam
);


wParam = virtual-key code
lParam = Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag.


Необходимо получить символ. Не пойму почему не получаеться. Т.е. получаеться, но только один раз и только на английском(на русском не правильно определяет)..
и еще после вызова функции ToUnicode функция, которой она была вызвана больше не работает.. т.е. как будто "ломается" хук.

вот как делаю сообствено:
чтобы получить Scan-Code, нужно, по идее, lParam and $FF0000

var
 Buf: Char;
 kbState: TKeyboardState;
...
GetKeyboardState(kbState);
ToUnicode(wParam,(lParam and $FF0000),kbState,Buf,1,0);


 
MInd_f ©   (2007-06-23 20:42) [1]

хммм... функция заработала.. странно. ведь ничего и не менял.

теперь остаеться вопрос:
как заставить ее правильно переводить в зависимости от раскладки?
**не знаю как сказать правильней. но думаю смысл ясен.


 
Leonid Troyanovsky ©   (2007-06-24 11:19) [2]


> MInd_f ©   (23.06.07 20:42) [1]

> как заставить ее правильно переводить в зависимости от раскладки?


Во-первых, раз уж юникод, то, по-крайней мере, buf: WChar,
а, в общем случае, array [0..1] of WChar.

Во-вторых, оная функция, в отличии от ToUnicodeEx, как раз,
и использует текущую раскладку вызывающего потока.

--
Regards, LVT.


 
MInd_f ©   (2007-06-24 12:13) [3]

> Leonid Troyanovsky ©   (24.06.07 11:19) [2]
Спасибо. Все работает.

var
 Buf: WChar;
 kbState: TKeyboardState;
 keybLayout: HKL;
 tmp:Integer;
begin
...
GetKeyboardState(kbState);
KeybLayout:=GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow, nil));
tmp:=ToUnicodeEx(wParam,(lParam And $FF0000),@kbState,@Buf,(lParam AND $FFFF),0, keybLayout);
...
end;


 
MInd_f ©   (2007-06-24 12:19) [4]

вот только еще вопрос..
в Keystroke Message Flags есть такая штука как Repeat Count (это первые 16 бит).
Я предполагал, что в буфер занесеться столько символов сколько было в Repeat Count. Но нет.  
вот это (lParam AND $FFFF) всегда возвращает еденицу.
зачем тогда array [0..1] of WChar?


 
Leonid Troyanovsky ©   (2007-06-24 12:30) [5]


> MInd_f ©   (24.06.07 12:19) [4]

> зачем тогда array [0..1] of WChar?


msdn: ToUnicode Function

Return Value

The function returns one of the following values.

Value Meaning
—1 The specified virtual key is a dead-key character (accent or diacritic). This value is returned regardless of the keyboard layout, even if several characters have been typed and are stored in the keyboard state. If possible, even with Unicode keyboard layouts, the function has written a spacing version of the dead-key character to the buffer specified by pwszBuff. For example, the function writes the character SPACING ACUTE (0x00B4), rather than the character NON_SPACING ACUTE (0x0301).
0 The specified virtual key has no translation for the current state of the keyboard. Nothing was written to the buffer specified by pwszBuff.
1 One character was written to the buffer specified by pwszBuff.
2 or more Two or more characters were written to the buffer specified by pwszBuff. The most common cause for this is that a dead-key character (accent or diacritic) stored in the keyboard layout could not be combined with the specified virtual key to form a single character. However, the buffer may contain more characters than the return value specifies. When this happens, any extra characters are invalid and should be ignored.

Т.е., даже не 2, а  в общем случае - более,
попутал с ToAscii, sorry.

--
Regards, LVT.


 
MInd_f ©   (2007-06-24 13:17) [6]

> Leonid Troyanovsky ©   (24.06.07 12:30) [5]

описание функции я читал.. но опытным путем не записывалось болие чем один символ в буфер. ладно, это по сути уже не важно. спасибо. с этим я разобрался.

..назрел еще вопрос, но не в этой теме.



Страницы: 1 вся ветка

Текущий архив: 2008.01.27;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.021 c
3-1190408298
Kostafey
2007-09-22 00:58
2008.01.27
Использование таблиц и полей в качестве параметров хранимых про-


2-1198681178
fics
2007-12-26 17:59
2008.01.27
TCanvas (нарисовать стрелочку)


2-1198592934
@!!ex
2007-12-25 17:28
2008.01.27
Перехват нажатия Win.


15-1198170241
NeLd
2007-12-20 20:04
2008.01.27
Посоветуйте пожалуйста LCD монитор за 25 kilorur.


15-1198055878
Kolan
2007-12-19 12:17
2008.01.27
Delphi не ищет в подпапках SearchPath.