greymouse Posted March 13, 2011 Share Posted March 13, 2011 (edited) So i need to have 10 ispressed, and that is just too many. Any better way for a workaround to create for the numbers 0-9? And hotkeyset is just going to take over 0-9 on the keyboard for later use. This is the code, just overkill to use 10 of them. I think it's going to slow down my script a lot. If _IsPressed("30") Then consolewrite("yeh") While _IsPressed("30") Sleep(10) WEnd Else Sleep(10) EndIf Edited March 13, 2011 by greymouse Link to comment Share on other sites More sharing options...
ChrisL Posted March 13, 2011 Share Posted March 13, 2011 For $i = 0 to 9 HotkeySet($i,"_HotKey") Next HotKeySet("{esc}","_Quit") While 1 sleep(250) WEnd Func _HotKey() ConsoleWrite(@HotKeyPressed & " Pressed" & @crlf) HotKeySet(@HotKeyPressed) Send(@HotKeyPressed) HotKeySet(@HotKeyPressed,"_HotKey") EndFunc Func _Quit() Exit EndFunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
greymouse Posted March 13, 2011 Author Share Posted March 13, 2011 @ChrisL, isn't that going to destroy another script? I mean i use those numbers for one script, then run another that sending the keys 0-9. I think it's not going to work so good. Link to comment Share on other sites More sharing options...
ChrisL Posted March 13, 2011 Share Posted March 13, 2011 Have you tried it or are you just going to say it wont work? [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
greymouse Posted March 13, 2011 Author Share Posted March 13, 2011 Have you tried it or are you just going to say it wont work?It works, but it destroying the 0-9 keys for my other script.And if i do a hotkeyset on the other script, it will destroy for the recent script. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 13, 2011 Moderators Share Posted March 13, 2011 greymouse,Look at GUISetAccelerators - it makes keys act in a similar fashion to HotKeys, but they only do so when your GUI is focused. That might help you. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
ChrisL Posted March 13, 2011 Share Posted March 13, 2011 So i need to have 10 ispressed, and that is just too many.Any better way for a workaround to create for the numbers 0-9?And hotkeyset is just going to take over 0-9 on the keyboard for later use.This is the code, just overkill to use 10 of them.I think it's going to slow down my script a lot.If _IsPressed("30") Then consolewrite("yeh") While _IsPressed("30") Sleep(10) WEnd Else Sleep(10) EndIfYou didn't say you wanted 2 scripts with hotkeyset for the same keys, you said it would be slow and you wanted to send keys 0 to 9 from another script.You could try 1 script with the hotkeys set for 0 to 9 and then you will have to use 1 of the inter script communication UDFs to share that information between the multiple scripts.Perhaps if you give more precise information about what you are trying to achieve you'd get a more precise response. [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
greymouse Posted March 13, 2011 Author Share Posted March 13, 2011 (edited) greymouse,Look at GUISetAccelerators - it makes keys act in a similar fashion to HotKeys, but they only do so when your GUI is focused. That might help you. M23Does it need button or something to work?Because i use pictures instead. And does it work with array?I tested with a array there the picture-id is stored, but didn't work at all.You didn't say you wanted 2 scripts with hotkeyset for the same keys, you said it would be slow and you wanted to send keys 0 to 9 from another script.You could try 1 script with the hotkeys set for 0 to 9 and then you will have to use 1 of the inter script communication UDFs to share that information between the multiple scripts.Perhaps if you give more precise information about what you are trying to achieve you'd get a more precise response.I don't want two scripts with hotkeyset.I just want one with they keys. But if i use hotkey in one, i need to use it in the other script.The first using 0-9 to change stuff. The other one is going to send 0-9.So if i close the first one, then open the other it works perfect. But if i have the script with hotkey binded and then open the other one, it doesn't work because it's going to disable the sending keys. Edited March 13, 2011 by greymouse Link to comment Share on other sites More sharing options...
ChrisL Posted March 13, 2011 Share Posted March 13, 2011 (edited) If only 1 script has HotKeySet in I don't see why it will disable the second script from sending the keys. If you look at what I wrote before it... 1 Sets the hotkey 2 traps the key 3 disables the hotkey 4 sends the key on 5 re-enables the hotkey So create 2 scripts. Number 1 ;1 For $i = 0 to 9 HotkeySet($i,"_HotKey") Next HotKeySet("{esc}","_Quit") While 1 sleep(250) WEnd Func _HotKey() ConsoleWrite(@HotKeyPressed & " Pressed" & @crlf) ;2 HotKeySet(@HotKeyPressed) ;3 Send(@HotKeyPressed) ;4 HotKeySet(@HotKeyPressed,"_HotKey") ;5 EndFunc Func _Quit() Exit EndFunc Number 2 Run("Notepad.exe") WinWait("Untitled") Send(0) Send(1) Send(2) Send(3) Send(4) Send(5) Send(6) Send(7) Send(8) Send(9) If you compile script number 1 as a console application from Scite and run it, then run script number 2, you will see that script 2 will send the keys 0 to 9, script 1 will capture them but the notepad window will still get the numbers 0 to 9 written in the text document because the function releases the key and sends it on. Edit: added some numbers in to script 1 so hopefully you can follow what it's doing Edited March 13, 2011 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Mat Posted March 13, 2011 Share Posted March 13, 2011 Try The way I'd do it would be an array, with each element having the hex code for the key (if you are just using the numbers one to nine then that may not be needed) and then what send to the console if it's pressed. You can then have another element that stores whether it is currently pressed as well.#include<Misc.au3> Local $a[9][3] = [ _ ["31", "1 pressed", False], _ ["32", "2 pressed", False], _ ["33", "3 pressed", False], _ ["34", "4 pressed", False], _ ["35", "5 pressed", False], _ ["36", "6 pressed", False], _ ["37", "7 pressed", False], _ ["38", "8 pressed", False], _ ["39", "9 pressed", False]] While 1 For $i = 0 to 8 If _IsPressed($a[$i][0]) Then If $a[$i][2] Then ContinueLoop ConsoleWrite($a[$i][1] & @CRLF) $a[$i][2] = True ElseIf $a[$i][2] Then $a[$i][2] = False EndIf Next Sleep(10) WEndOf course this can be simplified greatly to just the following if all you want is the numbers:#include<Misc.au3> Local $a[10] While 1 For $i = 0 to 9 If _IsPressed("3" & $i) Then If $a[$i] Then ContinueLoop ConsoleWrite($i & " pressed." & @CRLF) $a[$i] = True ElseIf $a[$i] Then $a[$i] = False EndIf Next Sleep(10) WEndMat AutoIt Project Listing Link to comment Share on other sites More sharing options...
greymouse Posted March 13, 2011 Author Share Posted March 13, 2011 Thanks for all help and examples guys. I using the guiaccelerator. And it works perfect now. Link to comment Share on other sites More sharing options...
Carlo84 Posted March 14, 2011 Share Posted March 14, 2011 (edited) greymouse,Look at GUISetAccelerators - it makes keys act in a similar fashion to HotKeys, but they only do so when your GUI is focused. That might help you. M23Thanks so much, i have been using this horrible script in the past, i did not know about these acceleratorsIf BitAND(WinGetState($gui), 8) Then If _IsPressed('11', $ipDll) And _IsPressed('4E', $ipDll) Then _mNew() ElseIf _IsPressed('11', $ipDll) And _IsPressed('4F', $ipDll) Then _mOpen() ElseIf _IsPressed('11', $ipDll) And _IsPressed('10', $ipDll) And _IsPressed('53', $ipDll) Then _mSave() ElseIf _IsPressed('11', $ipDll) And _IsPressed('53', $ipDll) Then _mSave($openFile) ElseIf _IsPressed('74', $ipDll) Then _mGo() ElseIf _IsPressed('11', $ipDll) And _IsPressed('76', $ipDll) Then _mCompile($openFile) EndIf EndIfQuestion though will GUISetAccelerators() handle both Ctrl+S and Ctrl+Shift+S properly?[Edit] yes works great :-) Edited March 14, 2011 by Djarlo _SplashProgressImage | _Regionselector | _IsPressed360 | _UserAccountContol_SetLevel | _ListSubFolders 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