pickle5 Posted July 26, 2008 Share Posted July 26, 2008 (edited) 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 July 26, 2008 by pickle5 Link to comment Share on other sites More sharing options...
Andreik Posted July 26, 2008 Share Posted July 26, 2008 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 More sharing options...
pickle5 Posted July 26, 2008 Author Share Posted July 26, 2008 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. Link to comment Share on other sites More sharing options...
Andreik Posted July 26, 2008 Share Posted July 26, 2008 (edited) 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. Edited July 26, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
pickle5 Posted July 26, 2008 Author Share Posted July 26, 2008 (edited) Errm I just tried it and it didn't work. Where do I put the function? Edited July 26, 2008 by pickle5 Link to comment Share on other sites More sharing options...
Andreik Posted July 26, 2008 Share Posted July 26, 2008 Thank you very much. You're welcome.You can learn more about dlls from help file. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
pickle5 Posted July 26, 2008 Author Share Posted July 26, 2008 You're welcome.You can learn more about dlls from help file. I actually dont think its working because I didnt place it in the right place where should it be placed? Link to comment Share on other sites More sharing options...
Andreik Posted July 26, 2008 Share Posted July 26, 2008 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 More sharing options...
James Posted July 26, 2008 Share Posted July 26, 2008 (edited) 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 July 26, 2008 by JamesBrooks Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
pickle5 Posted July 26, 2008 Author Share Posted July 26, 2008 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 More sharing options...
James Posted July 26, 2008 Share Posted July 26, 2008 GUICtrlSetBkColor() Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
pickle5 Posted July 26, 2008 Author Share Posted July 26, 2008 (edited) 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 July 26, 2008 by pickle5 Link to comment Share on other sites More sharing options...
James Posted July 26, 2008 Share Posted July 26, 2008 If GetKeyState("Key") = 0 Then GUICtrlSetBkColor(Def) You will have to find the default colour yourself. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
pickle5 Posted July 26, 2008 Author Share Posted July 26, 2008 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. Link to comment Share on other sites More sharing options...
NELyon Posted July 26, 2008 Share Posted July 26, 2008 #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 More sharing options...
pickle5 Posted July 26, 2008 Author Share Posted July 26, 2008 Is GetKeyState a function with autoit or does it have to be made? Link to comment Share on other sites More sharing options...
pickle5 Posted July 26, 2008 Author Share Posted July 26, 2008 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now