Jump to content
Sign in to follow this  
pickle5

Help With Hotkeys

Recommended Posts

pickle5

When I press the button for the hotkey to change the colour of my label it changes it but I want to be able to when I let go it changes back to the original colour. For example I would like to know how to change the label to red when held down and when let go it goes back to white.

If anyone knows how to do this please tell me. And if I didn't explain this enough I will try to explain better if someone asks me too.

Edited by pickle5

Share this post


Link to post
Share on other sites
Andreik

When I press the button for the hotkey to change the colour of my label it changes it but I want to be able to when I let go it changes back to the original colour. For example I would like to know how to change the label to red when held down and when let go it goes back to white.

If anyone knows how to do this please tell me. And if I didn't explain this enough I will try to explain better if someone asks me too.

Maybe help this function:

; Get Key State Pressed/Released

; Author - Toady

Func GetKeyState($VK_Code)
    Local $a_Return = DllCall("user32.dll","short","GetKeyState","int",$VK_Code)
    If $a_Return[0] < -126 Then
        Return 1   ;Key is pressed
    Else
        Return 0   ;Key is released
    EndIf
EndFunc

When the words fail... music speaks

Share this post


Link to post
Share on other sites
pickle5

Well it might work but I didnt try it yet. I do not understand anything about dll functions or whatever so if its possible could your explain what the code means?

Thanks.

Share this post


Link to post
Share on other sites
Andreik

Well it might work but I didnt try it yet. I do not understand anything about dll functions or whatever so if its possible could your explain what the code means?

Thanks.

This function return value 1 if one key (selected by you) is pressed and value 0 if the key is released.

This should help you to do what you want. :P

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites
pickle5

Errm I just tried it and it didn't work. Where do I put the function?

Edited by pickle5

Share this post


Link to post
Share on other sites
Andreik

Thank you very much. :P

You're welcome.

You can learn more about dlls from help file. :P


When the words fail... music speaks

Share this post


Link to post
Share on other sites
pickle5

You're welcome.

You can learn more about dlls from help file. :P

I actually dont think its working because I didnt place it in the right place where should it be placed?

Share this post


Link to post
Share on other sites
Andreik

I actually dont think its working because I didnt place it in the right place where should it be placed?

Here is an example, you can do best:

; Get Key State Pressed/Released

; Author - Toady
#include <Misc.au3>
Func GetKeyState($VK_Code)
    Local $a_Return = DllCall("user32.dll","short","GetKeyState","int",$VK_Code)
    If $a_Return[0] < -126 Then
        Return 1  ;Key is pressed
    Else
        Return 0  ;Key is released
    EndIf
EndFunc

$GUI = GUICreate("",150,50,-1,-1)
$LABEL = GUICtrlCreateLabel("TEST",5,5,140,40,0x01)
GUISetState()

While 1
    If _IsPressed('41') Then
        If GetKeyState(0x41) Then
            GUICtrlSetColor($LABEL,0xFF0000)
        Else
            GUICtrlSetColor($LABEL,0x000000)
        EndIf
    ElseIf GUIGetMsg() = -3 Then
        Exit
    Else
        GUICtrlSetColor($LABEL,0x000000)
    EndIf
    Sleep(25)
WEnd

When the words fail... music speaks

Share this post


Link to post
Share on other sites
James

While 1
    Sleep(500)
    If GetKeyState("11") Then ConsoleWrite("Your pressing (I forgot which key 11 is!)" & @CRLF)
WEnd

Func GetKeyState($VK_Code)
    Local $a_Return = DllCall("user32.dll","short","GetKeyState","int",$VK_Code)
    If $a_Return[0] < -126 Then
        Return 1  ;Key is pressed
    Else
        Return 0  ;Key is released
    EndIf
EndFunc

Edited by JamesBrooks

Share this post


Link to post
Share on other sites
pickle5

Actually im back and I need more help. The problem is, is that that is just to change the text in the label and it doesnt work for changing the colour or the back colour of the label.

If anyone knows how to do this please help me.

Thanks.

Share this post


Link to post
Share on other sites
pickle5

GUICtrlSetBkColor()

I know that but when I did that it wouldn't go away after. I mean the colour wouldnt go back to normal.

Edited by pickle5

Share this post


Link to post
Share on other sites
pickle5

If GetKeyState("Key") = 0 Then GUICtrlSetBkColor(Def)

You will have to find the default colour yourself.

I will try this. It looks like it may work.

Share this post


Link to post
Share on other sites
NELyon

#include <WindowsConstants.au3>
#include <Misc.au3>
HotKeySet("{F11}", "_LightOnTemp")
Global $hBkColor = 0xFFFFFF
$hGUI = GUICreate("Cool", 200, 200, -1, -1, BitOR($WS_POPUP, $WS_SIZEBOX))
$hLight = GUICtrlCreateLabel("", 0, 0, 200, 200)
GUICtrlSetBkColor($hLight, $hBkColor)
GUISetState()
While 1
    Sleep(200)
WEnd

Func _LightOnTemp()
    $hBkColor = 0xFF4444
    GUICtrlSetBkColor($hLight, $hBkColor)
    Do
        Sleep(20)
    Until Not _IsPressed("7A")
    $hBkColor = 0xFFFFFF
    GUICtrlSetBkColor($hLight, $hBkColor)
EndFunc   ;==>_LightOnTemp

Does exactly what you want.

Share this post


Link to post
Share on other sites
pickle5

Is GetKeyState a function with autoit or does it have to be made?

Share this post


Link to post
Share on other sites
pickle5

Thats what I needed!

Now for sure I think this is it lol.

Thanks for everyones help. And there was something I might need to ask later lol.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×