Jump to content

Get arrow keys by Windows Message Code


Recommended Posts

Hi forum!

Is possible get when any arrow keys (right, up, left, down) is pressed by Windows Message Code?

I have a piece of code with _IsPressed, and work very fine!

But the diference is _IsPressed I need put in loop and by Windows Message Code no, is not necessary, is correct?

In my search I cant found a example to do this...

Some one can help me?

 

Br, Luigi

-snipped-

Edited by Jos
code removed

Visit my repository

Link to comment
Share on other sites

HotKeySet() does not burn cpu.

See this sample

_HotKey("{ESC}")
_HotKey("{left}")
_HotKey("{right}")
_HotKey("{up}")
_HotKey("{down}")
Func _HotKey($hotkey = "")
;       ! ALT  + SHIFT  ^ CONTROL  # WinKey

    Switch @HotKeyPressed

        Case "{ESC}"
            Exit 0*MsgBox(64 + 262144, Default, "Exit", 1)
        Case "{left}"
            beep(1000,100)
        Case "{right}"
            beep(1500,100)
        Case "{up}"
            beep(2000,100)
        Case "{down}"
            beep(2500,100)
        Case Else
            If Not IsDeclared("hotkey") Then Return MsgBox(16 + 262144, Default, "No CASE statement defined for hotkey " & @HotKeyPressed)
            If HotKeySet($hotkey, "_Hotkey") = 0 Then Return MsgBox(16 + 262144, Default, "Hotkey " & $hotkey & " invalid or set by another application.")
    EndSwitch

EndFunc   ;==>_HotKey



While Sleep(99999999)     ; this takes minimalst cpu
WEnd

 

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Two comand in same line? (o.O)

Exit 0*MsgBox(64 + 262144, Default, "Exit", 1)

Thank you Exit, your example work very well and burn low cpu, realy!

But I need combine the keys:

  • up, up+left, up+down
  • down, down+left, down+right
  • right, right+down, right+left
  • left, left+down, left+right

Maybe your example not let do this...

 

 

Visit my repository

Link to comment
Share on other sites

Using multiple keys

#include <Misc.au3>
_HotKey("{ESC}")
_HotKey("{left}")
_HotKey("{up}")
_HotKey("{right}")
_HotKey("{down}")
Func _HotKey($hotkey = "")
    ;       ! ALT  + SHIFT  ^ CONTROL  # WinKey



    Switch @HotKeyPressed



        Case "{ESC}"
            Exit 0 * MsgBox(64 + 262144, Default, "Exit", 1)
        Case "{left}", "{up}", "{right}", "{down}"
            Sleep(100)  ; allow other keys to be pressed

            $text = ""
            $text &= (_IsPressed(25) ? "Left " : "")
            $text &= (_IsPressed(26) ? "Up " : "")
            $text &= (_IsPressed(27) ? "Right " : "")
            $text &= (_IsPressed(28) ? "Down " : "")
            if $text > "" then MsgBox(262144, Default, $text, 1)
        Case Else
            If Not IsDeclared("hotkey") Then Return MsgBox(16 + 262144, Default, "No CASE statement defined for hotkey " & @HotKeyPressed)
            If HotKeySet($hotkey, "_Hotkey") = 0 Then Return MsgBox(16 + 262144, Default, "Hotkey " & $hotkey & " invalid or set by another application.")
    EndSwitch



EndFunc   ;==>_HotKey



While Sleep(99999999) ; this takes minimalst cpu
WEnd

 

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

@Exit, I will try your example, thanks! ^^
It is news for me!

In time...

If found this AZJIO's example:

It cath/get arrow keys when you release it, when you press, not get the key... Any idea?

 

-snip-

Edited by Jos

Visit my repository

Link to comment
Share on other sites

WM_KEYDOWN does not fire when you press an arrow key in an empty GUI. Use a hook procedure:

-snip-
Edited by Jos
Link to comment
Share on other sites

Thank you @Larsj, work nice! It's not necessary a loop for detect when a keyup!

WM_KEYDOWN does not fire when you press an arrow key in an empty GUI. Use a hook procedure:

Hum...empty GUI? If have a element (button, label, any) it's work?

 

 

Visit my repository

Link to comment
Share on other sites

If you add an input control or an edit control and one of these controls has the keyboard focus I think it'll work. These controls are supposed to handle key down/up events.

Link to comment
Share on other sites

An alternative way to _IsPressed() is the use of WM_INPUT, interesting because it works even if the gui is not in the foreground

Before use, Important : first  fix the current $tagRAWKEYBOARD  typo in WinAPISys.au3 as mentioned in the code

-snipped -

Edited by Jos
Link to comment
Share on other sites

  • Developers

This is getting close to a full keylogger which we have been clear about ...right?

Code will be removed.

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...