Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Система";
Текущий архив: 2003.02.10;
Скачать: [xml.tar.bz2];

Вниз

Есть ли ф-я, к-рая преобразует код символа в скан-код клавиши?   Найти похожие ветки 

 
sw   (2002-12-03 04:02) [0]

Подскажите, кто знает, есть ли функция, которая преобразует код символа в скан-код клавиши.
Первоначальная задача такая:
Как, зная код символа, полученный по KeyPressed(Sender: TObject; var Key: Char) проверить - нажата ли клавиша в текущий момент, т.е. вызвать ф-ю GetAsyncKeyState, которая требует скан-код клавиши.


 
Song   (2002-12-03 08:40) [1]

MapVirtualKey()


 
sw   (2002-12-03 09:41) [2]

Увы, не подходит. Я запускал эту функцию с параметрами 0, 1, 2 и 3 для кода буквы "Ф" - результат нулевой


 
sniknik   (2002-12-03 10:51) [3]

для буквы "Ф" его и не будет, 0 невозможно преобразовать. посмотри ее значение (Ord) чему равно? а клавиш всего 101шт. (но не все так просто, 101 это наоборот скэн коды надо считать)

в твоем случае букву "Ф" надо переводить в анг. вариант "A" и тогда MapVirtualKey(Key,0) дает скэн код. короче не работает с MapVirtualKey с локализованными раскладками а AnsiMapVirtualKey пока нет.

путано обьяснил? могу послать програмку тест, или сам сделай повесь на кейпресс процедурку, что делать дальше разберешся

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var st: string;
begin
if WinKey < Key then begin
WinKey:= Key;
Edit1.Text:= "Key : "+IntToStr(Key)+" Char : "+Chr(Key);
end;
// MapVirtualKey
Memo1.Lines.Add("Key : "+IntToStr(Key)+" Char : "+Chr(Key)+" MVK : "+IntToStr(MapVirtualKey(Key,0)));
if ssShift in Shift then st:= "1"
else st:= "0";
if ssAlt in Shift then st:= st + "1"
else st:= st+"0";
if ssCtrl in Shift then st:= st + "1"
else st:= st+"0";

if ssLeft in Shift then st:= st + "1"
else st:= st+"0";
if ssRight in Shift then st:= st + "1"
else st:= st+"0";
if ssMiddle in Shift then st:= st + "1"
else st:= st+"0";
if ssDouble in Shift then st:= st + "1"
else st:= st+"0";
Memo1.Lines.Add("State Shift/Alt/Ctrl/Left/Right/Middle/Double : "+st);
{ GetNumberofConsoleInputEvents
if Key = VK_RIGHT then Form1.Caption := "Right";
if Key = VK_F1 then Form1.Caption := "F1";
WM_KEYDOWN
MapVirtualKeyEx, OemKeyScan, VkKeyScanEx
}

end;


 
Севостьянов Игорь   (2002-12-03 11:00) [4]

GetAsyncKeyState
The GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.

SHORT GetAsyncKeyState(
int vKey // virtual-key code
);
Parameters
vKey
[in] Specifies one of 256 possible virtual-key codes. For more information, see Virtual-Key Codes.
Windows NT/2000: You can use left- and right-distinguishing constants to specify certain keys. See the Remarks section for further information.

Return Values
If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. The return value is zero if a window in another thread or process currently has the keyboard focus.

Windows 95: Windows 95 does not support the left- and right-distinguishing constants. If you call GetAsyncKeyState with these constants, the return value is zero.
Remarks
The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system"s current mapping of physical mouse buttons to logical mouse buttons by calling

GetSystemMetrics(SM_SWAPBUTTON)
which returns TRUE if the mouse buttons have been swapped.

You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right.

Windows NT/2000: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys.

Code Meaning
VK_LSHIFT VK_RSHIFT
VK_LCONTROL VK_RCONTROL
VK_LMENU VK_RMENU


These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.

Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.

See Also
Keyboard Input Overview, Keyboard Input Functions, GetKeyboardState, GetKeyState, GetSystemMetrics, MapVirtualKey, SetKeyboardState


 
sw   (2002-12-04 06:29) [5]

Вообще-то хэлп я читал и тестовую программку писал до того как задал вопрос



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

Форум: "Система";
Текущий архив: 2003.02.10;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.01 c
1-28740
Alex G
2003-01-31 23:09
2003.02.10
Проблема сортировки... Украинские слова


1-28709
Areon
2003-01-31 08:22
2003.02.10
Подмена имени


1-28711
ST
2003-01-31 15:42
2003.02.10
TWebBrowser: сорнанение HTML кода на диск.


1-28707
DiXO
2003-01-31 14:57
2003.02.10
Быстрый поиск по DBGridу


1-28737
Son!K
2003-01-31 21:51
2003.02.10
Проценты





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский