Jump to content

Help With Hotkeys


Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

#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.

Link to comment
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
 Share

  • Recently Browsing   0 members

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