Jump to content
Sign in to follow this  
Luigi

Get arrow keys by Windows Message Code

Recommended Posts

Luigi

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

Share this post


Link to post
Share on other sites
Exit

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

 


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
Luigi

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

Share this post


Link to post
Share on other sites
reb

Try This Sory this does not work correctly. I will check later to find out what is wrong with it.

 

Local $Out = 0
HotKeySet("{UP}{DOWN}","UPDOWN")

do
    Sleep(10)
Until $Out = 1

Func UPDOWN()
    MsgBox(0,"","UP Down Presses")
    $Out = 1
EndFunc

 

Edited by reb

MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites
Exit

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

 


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
Luigi

@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

Share this post


Link to post
Share on other sites
LarsJ

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

-snip-
Edited by Jos
  • Like 1

Share this post


Link to post
Share on other sites
Luigi

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

Share this post


Link to post
Share on other sites
LarsJ

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.

Share this post


Link to post
Share on other sites
mikell

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

Share this post


Link to post
Share on other sites
Luigi

@mikell, your code work too! Thank you!

8D

 


Visit my repository

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×