Tastatur lesen
-
Mein Programm läuft unsichtbar im Hintergrund und berechnet gewisse Daten.. Das ist alles gut soweit. Wenn nun der User die taste -- F -- drückt muss das Programm eine Messagebox ausgeben. Wie kann ich sowas erreichen ohne DLL's oder sonnstige zusätzliche Dateien?
WM_KEYDOWN geht irgendwie nicht
-
RegisterHotkey()
MfG Spacelord
-
leider hab ich zu RegisterHotkey() weder bei google noch im Forum hier wa schlaues gefunden udn die MSDN hilft mer nicht recht weiter :S
-
Auszug aus eine Hilfe für win32 API:
The RegisterHotKey function defines a hot key for the current thread.
BOOL RegisterHotKey(
HWND hWnd, // window to receive hot-key notification
int id, // identifier of hot key
UINT fsModifiers, // key-modifier flags
UINT vk // virtual-key code
);
ParametershWnd
Identifies the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop.
id
Specifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier.
fsModifiers
Specifies keys that must be pressed in combination with the key specified by the nVirtKey parameter in order to generate the WM_HOTKEY message. The fsModifiers parameter can be a combination of the following values:
Value Meaning
MOD_ALT Either ALT key must be held down.
MOD_CONTROL Either CTRL key must be held down.
MOD_SHIFT Either SHIFT key must be held down.
vkSpecifies the virtual-key code of the hot key.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.Remarks
When a key is pressed, the system looks for a match against all thread hot keys. Upon finding a match, the system posts the WM_HOTKEY message to the message queue of the thread that registered the hot key. This message is posted to the beginning of the queue so it is removed by the next iteration of the message loop.
This function cannot associate a hot key with a window created by another thread.
RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key.If the window identified by the hWnd parameter already registered a hot key with the same identifier as that specified by the id parameter, the new values for the fsModifiers and vk parameters replace the previously specified values for these parameters.
See Also
GlobalAddAtom, UnregisterHotKey, WM_HOTKEY
-
hmm dnake für die mühe bleib aber dennoch hängen
-
Weshalb geht es mit case WM_KEYDOWN: Nicht???????????
-
WM_KEYDOWN geht nicht, weil dein Programm nicht den Focus hat und somit auch kein WM_KEYDOWM bekommt. Den Hotkey sollte ein STRG+ALT+F sein. Nur ein F ist problematisch, da dein Programm auch aufgerufen wird wenn du im Editor das Wort Bratpfanne schreibst. ALT+F oder STRG+F sind auch schlecht, da manche Programme dies als Menukürzel...
-
Es muss nicht F sein es kann auch ein anderen Buchstabe sein. Egal ich will einfach eine Funktion ausführen wenn eine Tastegedrückt wird udn das kapier ich hinten udn vorne nicht
Vorallem wie der COde aussehen muss :S
-
verwenden.
-
Wo ist dein Problem mit RegisterHotkey
Und wie schon gesagt wurde solltest du nich einen einzelnen Buchstaben verwenden
-
irgendwie funzt der kakk nicht
kennt jemand ein kleines code BSP im Netz??? währe cht dnakbar da ich an diesem Problem nun schon tage hängenbleibe und nicht weiter komme
-
Ja. In der Borland C++Builder FAQ gibt's ein Beispiel. Wenn du bei der FAQ angelangt bist, dann wähle die Index-Page (ist glaub ich der 2. Thread in den FAQ). Dort sind alle Themen schön sortiert.
[EDIT]
OK, ich verlink dich. Hab ja Zeit...Tasten - Systemweite Hotkeys à la ICQ
[/EDIT][ Dieser Beitrag wurde am 12.04.2003 um 14:43 Uhr von WebFritzi editiert. ]
-
RegisterHotKey(NULL,ID_MYHOTKEY,MOD_ALT|MOD_SHIFT,VK_F7);
z.B. für Alt-Shift-F7
Jetzt musst du in deiner Message-Loop nur noch WM_HOTKEY bearbeiten.
Wo liegt dein Problem?Ps: Du musst ID_MYHOTKEY mit #define einen Wert zuweisen.
MfG Spacelord
[ Dieser Beitrag wurde am 12.04.2003 um 14:46 Uhr von Spacelord editiert. ]
-
Original erstellt von Spacelord:
**RegisterHotKey(NULL,ID_MYHOTKEY,MOD_ALT|MOD_SHIFT,VK_F7);
z.B. für Alt-Shift-F7
Jetzt musst du in deiner Message-Loop nur noch WM_HOTKEY bearbeiten.
Wo liegt dein Problem?Ps: Du musst ID_MYHOTKEY mit #define einen Wert zuweisen.
**und dabei hab ich auch ein problem..
*
id
[in] Specifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier.*kann mir das mal einer erklären?!
vorallem wie benutz ich hier GlobalAddAtom?!? und was ist hier ein atom?!
-
Willst du das ganze denn überhaupt in eine dll stecken? Ansonten nimmt halt irgendeinen Wert zwischen 0x0000 und 0xBFFF
-
Man sollte Werte oberhalb von 1000 nehmen um Konflikte zu vermeiden.
Hab ich zumindest irgendwie so in Erinnerung.
MfG Spacelord
-
ich hab das jetzt mal ausprobiert geht auch wunderbar nur:
ich habe ein programm das nen timer(mit proc) aufruft und dinge tut..
dies soll solange getan werden bis ne abbruchbedingung kommt..
geht auch prima (wenn ich alles ohne timer mache..)
wie kann ich das sonst machen?!
-> es geht nicht weil ich (denk ich) wenn ich das in den timer packe , genau dann drücken muss wenn die proc aufgerufen wird (richtig?!)aber ich möchte zu jedem zeitpunkt abbrechen können...
-
der timer ist jetzt zwar ungenau (egal..) aber es geht
-> ich benütz jetz die WM_TIMER und hab die proc weggelassen..
-
Erstell nen zweiten Thread der auf den Tastendruck wartet und deiner Schleife die Abruchbedingung signalisiert.
Wobei ich nich genau weiss was du in deinen Timer packst.
-
das Beispiel aus der FAQ "KeyboardHook" ist doch perfekt für dich.