Xichael Posted February 22, 2008 Share Posted February 22, 2008 (edited) I'm trying to find the send key code (or whatever it's called) for a funny little button on my laptop. I found this script somewhere in the forum:#include <misc.au3> While 1 sleep(10) For $i = 0 to 255 if (_IsPressed(Hex($i))) Then MsgBox(0, "", "You pressed the: " & Chr($i) & " Key!" & @CRLF & "Which would be polled with: _Ispressed(" & $i & ")") EndIf Next WEndPressing the button while this script is running tells me:You pressed the: ÿ Key! which would be polled with: _Ispressed(255)So how can I now use this information in a HotKeySet like in this script:#NoTrayIcon HotKeySet ("_IsPressed goes here?", "Monoff") While 1 Sleep(50) WEnd Func Monoff() Run("C:\Program Files\Monoff4.exe") EndFuncI've tried putting ÿ, _Ispressed(255), and just 255 in the HotKeySet, none of which worked. In AutoHotkey this button goes by SC112, but not so in AutoIt. How can I find and use this button's send key code?Your help is much appreciated... Edited February 24, 2008 by Xichael Link to comment Share on other sites More sharing options...
martin Posted February 22, 2008 Share Posted February 22, 2008 HotKeySet(Chr(225),"Monoff") Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Xichael Posted February 22, 2008 Author Share Posted February 22, 2008 HotKeySet(Chr(225),"Monoff")That didn't do it, sad to say... Any other suggestions? Link to comment Share on other sites More sharing options...
martin Posted February 23, 2008 Share Posted February 23, 2008 That didn't do it, sad to say... Any other suggestions? Only that maybe you could simply check using _IsPressed(225) in your main loop instead of using a hotkey. Something like while something;main loop . . . If _IsPressed(225) then Monoff() while _IsPressed(225) wend endif wend;end of main loop Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Xichael Posted February 23, 2008 Author Share Posted February 23, 2008 The If _IsPressed(255) then line has an "If ^ERROR" of an "unknown function name"... Then again, I don't really know how these things work (I'm new to AutoIt). How exactly would it fit into my script? I've tried:While 1 If _IsPressed(255) then Monoff() While _IsPressed(255) WEnd EndIf WEnd Func Monoff() Run("C:\Program Files\Monoff4.exe") EndFuncIs this roughly how it would work? Link to comment Share on other sites More sharing options...
Swift Posted February 23, 2008 Share Posted February 23, 2008 Yes! Link to comment Share on other sites More sharing options...
Xichael Posted February 23, 2008 Author Share Posted February 23, 2008 Why the error when I run it? Link to comment Share on other sites More sharing options...
Brickoneer Posted February 23, 2008 Share Posted February 23, 2008 Error messages are incredibly helpful. It doesn't know what _ispressed is. You probably forgot the include file. misc.au3 if I remember correctly. Link to comment Share on other sites More sharing options...
Xichael Posted February 23, 2008 Author Share Posted February 23, 2008 (edited) ...You probably forgot the include file. misc.au3...Thanks, that got rid of the error, but the script still doesn't work. What else could be missing? Edited February 23, 2008 by Xichael Link to comment Share on other sites More sharing options...
martin Posted February 23, 2008 Share Posted February 23, 2008 Error messages are incredibly helpful. It doesn't know what _ispressed is. You probably forgot the include file. misc.au3 if I remember correctly.Looks like you have written 255 but it should be 225 shouldn't it?You should add some debugging code if it still doesn't work. ConsoleWrite is very useful for that. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Xichael Posted February 24, 2008 Author Share Posted February 24, 2008 (edited) Sorry, the above 225 was a typo. I just fixed it. Will this still need a debugging now that there aren't any errors? The misc.au3 include fixed the error I was getting. Now my problem is that the script just won't do anything. I can't get any key to work with with IsPressed. For instance, _IsPressed(90), which should be the z key, won't run the function any more than 255 will... Here's the current script: #include <misc.au3> While 1 If _IsPressed(255) then Monoff() While _IsPressed(255) WEnd EndIf WEnd Func Monoff() Run("C:\Program Files\Monoff4.exe") EndFunc Can anyone tell me what's wrong? Edited February 24, 2008 by Xichael Link to comment Share on other sites More sharing options...
Achilles Posted February 24, 2008 Share Posted February 24, 2008 (edited) I tried editing this to see if it would work and it works fine for me: #include <misc.au3> While 1 If _IsPressed('5A') then Monoff() While _IsPressed('5A') WEnd EndIf WEnd Func Monoff() ConsoleWrite('!> Check...' & @CRLF) ;~ Run("C:\Program Files\Monoff4.exe") EndFuncTry to see if you are getting to the ConsoleWrite line I added. If you are then your Run command isn't working... Edit: '5A' = z Edited February 24, 2008 by Achilles My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
JustinReno Posted February 24, 2008 Share Posted February 24, 2008 I tried this on my MediaDirect button and start button but it didn't work Link to comment Share on other sites More sharing options...
Xichael Posted February 24, 2008 Author Share Posted February 24, 2008 (edited) '5A' = zIt's true, and the script is finally working! What are you using to find out that 5A = z? The script I'm using (posted above) tells me 90 = z... Could you post a copy of the IsPressed key revealing script that you're using? It would seem that the MediaDirect button isn't 255 at all. Edited February 24, 2008 by Xichael Link to comment Share on other sites More sharing options...
Achilles Posted February 24, 2008 Share Posted February 24, 2008 It's true, and the script is finally working! What are you using to find out that 5A = z? The script I'm using (posted above) tells me 90 = z... Could you post a copy of the IsPressed key revealing script that you're using? It would seem that the MediaDirect button isn't 255 at all.The helpfile is my magic book. Look up _IsPressed and it should have an incomplete but very long list. Look Contents --> AutoIt --> Appendix --> ASCII Characters for a complete list (in the helpfile also)... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Siao Posted February 24, 2008 Share Posted February 24, 2008 It's true, and the script is finally working! What are you using to find out that 5A = z? The script I'm using (posted above) tells me 90 = z... Could you post a copy of the IsPressed key revealing script that you're using? It would seem that the MediaDirect button isn't 255 at all.For the record, 0x5A = 90.And _IsPressed works correctly only if you pass hex string to it, it does not support numbers. "be smart, drink your wine" Link to comment Share on other sites More sharing options...
Xichael Posted February 24, 2008 Author Share Posted February 24, 2008 So the help file says 255 is FF, but when I run the script with FF, the function just runs immediately, without waiting for a keypress. This MediaDirect button obviously isn't 255/FF, so is there some other script that can output the proper dec/hex value of this button? The script I've used is either wrong, or there's just no way for AutoIt to detect this button. The latter would be odd, as AutoHotkey (which is based on AutoIt, no?) has no problem using it (MediaDirect button = SC112)... This can't be a lost cause, can it? Link to comment Share on other sites More sharing options...
Achilles Posted February 24, 2008 Share Posted February 24, 2008 I'm just guessing now, but it seems odd to me that the very last value in your for next loop is 255 and that's what you got for the value of your key. What happens if you have a loop that goes to 300 or something? That's probably won't work but who knows... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Siao Posted February 24, 2008 Share Posted February 24, 2008 (edited) If it involves scan codes, most likely you'll have to use keyboard hook. Luckily for you nowadays that isn't very complicated.Search forum for WH_KEYBOARD_LL.You'll have to get scan code from the structure passed as lParam in callback function.Edit: see this #450718 Edited February 24, 2008 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
Achilles Posted February 24, 2008 Share Posted February 24, 2008 If it involves scan codes, most likely you'll have to use keyboard hook. Luckily for you nowadays that isn't very complicated.Search forum for WH_KEYBOARD_LL.You'll have to get scan code from the structure passed as lParam in callback function.Edit: see this #450718That's what I was looking for... I remember someone had made this but couldn't find it. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] 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