Traddles Posted April 27, 2009 Share Posted April 27, 2009 (edited) So my code is supposed to behave as follows, I highlight some text and press ctrl+space, the script copies the selected text and goes and gets information from a bunch of files on my local machine and comes back with some useful information. At that point it displays a small gui with a single label displaying that information. The gui should stay up until I release the control key. This is what I have ... snip $lineLen = StringLen($line) $mouse = MouseGetPos() $gui = GUICreate("Definition", $lineLen*7, 50, 0, $mouse[1]) GUISetState(@SW_SHOW) $label = GUICtrlCreateLabel($line, 10, 25, ($lineLen*7), 30) While(True) Sleep(100) GUICtrlSetData($label, _IsPressed('11')) ; for debugging If (_IsPressed('11') == 0) Then ExitLoop EndIf WEnd msgbox(0, "pause", "don't kill the gui just yet so that we can see the result of _isPressed"); debugging GUIDelete($gui) This works fine except for one really weird thing. When I do left control + space it behaves exactly as I would expect, it quickly pops up a gui with the information and stays up until I've released left-control. But when I do right-control + space it brings up the gui but the gui stays up no matter what. I release all the keys on the keyboard and it stays up. It's only after I press in the left-control and release IT that the gui closes. Anybody have any ideas? *edit: added code tags Edited April 27, 2009 by Traddles Link to comment Share on other sites More sharing options...
martin Posted April 27, 2009 Share Posted April 27, 2009 So my code is supposed to behave as follows, I highlight some text and press ctrl+space, the script copies the selected text and goes and gets information from a bunch of files on my local machine and comes back with some useful information. At that point it displays a small gui with a single label displaying that information. The gui should stay up until I release the control key. This is what I have ... snip $lineLen = StringLen($line) $mouse = MouseGetPos() $gui = GUICreate("Definition", $lineLen*7, 50, 0, $mouse[1]) GUISetState(@SW_SHOW) $label = GUICtrlCreateLabel($line, 10, 25, ($lineLen*7), 30) While(True) Sleep(100) GUICtrlSetData($label, _IsPressed('11')) ; for debugging If (_IsPressed('11') == 0) Then ExitLoop EndIf WEnd msgbox(0, "pause", "don't kill the gui just yet so that we can see the result of _isPressed"); debugging GUIDelete($gui) This works fine except for one really weird thing. When I do left control + space it behaves exactly as I would expect, it quickly pops up a gui with the information and stays up until I've released left-control. But when I do right-control + space it brings up the gui but the gui stays up no matter what. I release all the keys on the keyboard and it stays up. It's only after I press in the left-control and release IT that the gui closes. Anybody have any ideas? *edit: added code tagsIt would be a lot easier for people to help if you could post some code which we could run and which is intended to show the problem Because I'm not sure what your code is doing, especially the missing code, I tried this, and it works for me whichever Ctrl key I use #include <misc.au3> $line = "abcdef" $lineLen = StringLen($line) $mouse = MouseGetPos() $gui = GUICreate("Definition", $lineLen * 7 + 50, 50, 0, $mouse[1]) GUISetState(@SW_SHOW) $label = GUICtrlCreateLabel($line, 10, 25, ($lineLen * 10), 30) While (True) Sleep(100) If _IsPressed('11') Then GUICtrlSetData($label, "Ctrl down"); for debugging $labelsettppressed = True ;do something While _IsPressed('11') Sleep(50) WEnd GUICtrlSetData($label, "Ctr up") ExitLoop EndIf WEnd MsgBox(0, "pause", "don't kill the gui just yet so that we can see the result of _isPressed"); debugging 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...
Traddles Posted April 27, 2009 Author Share Posted April 27, 2009 Ok, no problem. Here's a snipped down version of the complete working program, if you run this and try using ctrl+space using both control keys you should see what I'm talking about expandcollapse popup#include <WinAPI.au3> HotKeySet("^{SPACE}", "LookUpWord") While (True) Sleep(100) WEnd Func LookUpWord() $clipBuff = ClipGet() Send("^c") Sleep(10) $word = " "&ClipGet()&" " ClipPut($clipBuff) If ($word == " " Or $word == " " & $clipBuff & " ") Then Return EndIf ; snip bunch of stuff that opens files and stuff to get an actual definition for the word that was just coppied $line = "some definition for that word that was just copied into the clipboard" $lineLen = StringLen($line) $mouse = MouseGetPos() $gui = GUICreate("Definition", $lineLen*7, 50, 0, $mouse[1]) GUISetState(@SW_SHOW) $label = GUICtrlCreateLabel($line, 10, 25, ($lineLen*7), 30) While(True) Sleep(100) If (_IsPressed('11') == 0) Then ExitLoop EndIf WEnd GUIDelete($gui) EndFunc Link to comment Share on other sites More sharing options...
Yashied Posted April 27, 2009 Share Posted April 27, 2009 Try this. expandcollapse popup#include <WinAPI.au3> #include <Misc.au3> HotKeySet("^{SPACE}", "LookUpWord") While (True) Sleep(100) WEnd Func LookUpWord() $clipBuff = ClipGet() ; Send("^c") _keybd_event(0x43, 0x00) Sleep(100) _keybd_event(0x43, 0x02) $word = " "&ClipGet()&" " ClipPut($clipBuff) If ($word == " " Or $word == " " & $clipBuff & " ") Then Return EndIf ; snip bunch of stuff that opens files and stuff to get an actucal definition for the word that was just coppied $line = "some definition for that word that was just copied into the clipboard" $lineLen = StringLen($line) $mouse = MouseGetPos() $gui = GUICreate("Definition", $lineLen*7, 50, 0, $mouse[1]) GUISetState(@SW_SHOW) $label = GUICtrlCreateLabel($line, 10, 25, ($lineLen*7), 30) While(True) Sleep(10) If (_IsPressed('11') == 0) Then ExitLoop EndIf WEnd GUIDelete($gui) EndFunc func _keybd_event($vkCode, $Flag) DllCall('user32.dll', 'int', 'keybd_event', 'int', $vkCode, 'int', 0, 'int', $Flag, 'ptr', 0) endfunc; _keybd_event My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Traddles Posted April 27, 2009 Author Share Posted April 27, 2009 (edited) Ok, that worked.... but why? I'm an engineer and have a habit of not liking to run things that I don't understand. What is this dll call doing? DllCall('user32.dll', 'int', 'keybd_event', 'int', $vkCode, 'int', 0, 'int', $Flag, 'ptr', 0) and how does changing how I get the selected text fix my gui loop? *edit, forgot the code tags again Edited April 27, 2009 by Traddles Link to comment Share on other sites More sharing options...
WideBoyDixon Posted April 27, 2009 Share Posted April 27, 2009 It appears that the [Ctrl] key simulated press in the Send() call is never registered as being "up" again. _IsPressed("A2") returns 1 even when you're using the right control key to trigger the script. It will depend on how the underlying C++ code is implementing the functionality for Send(). Even the target application (SciTE in my case) thinks the left control key is down until you toggle it yourself by pressing it.Yashied's example uses a deprecated call (see http://msdn.microsoft.com/en-us/library/ms...04(VS.85).aspx) to synthesise the keystroke. Because you've already got [Ctrl] held down, it just sends a keydown/keyup event for the "c" key which effectively sends [Ctrl]C to the application.Hope that makes more sense for you.WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
Traddles Posted April 27, 2009 Author Share Posted April 27, 2009 I see, so basically doing Send("^c") doesn't actually send a "keyUp" signal? That seems bad to me. Although it does explain my problems. Link to comment Share on other sites More sharing options...
Yashied Posted April 28, 2009 Share Posted April 28, 2009 I see, so basically doing Send("^c") doesn't actually send a "keyUp" signal? That seems bad to me. Although it does explain my problems.It turns out that the Send("^c") does not work properly until RCTRL is hold down. I do not know why this is happening. If you do not fit my trick, then look for this forum way to copy to the clipboard without calling Send() function.Good luck. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Traddles Posted April 28, 2009 Author Share Posted April 28, 2009 No, your code worked fine and I appreciate it. I was just curious why sending the control key seems to behave weirdly like this. Is this an AutoIt bug? Link to comment Share on other sites More sharing options...
Yashied Posted April 28, 2009 Share Posted April 28, 2009 No, your code worked fine and I appreciate it. I was just curious why sending the control key seems to behave weirdly like this. Is this an AutoIt bug?Maybe. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... 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