Yodavish Posted October 9, 2019 Posted October 9, 2019 (edited) Hello AutoIt, I'm new to Autoit and I'm trying to play an alert sound when a barcode is scanned in while a certain window is still active. A typical barcode scan would be something like this: "AA19-1234" followed by a carriage return/enter. My original thought was to have it within a loop, and check if the "SumatraPDF" is active and if an "Enter" is sent when a barcode is accidentally scanned. But it doesn't work when I scan a barcode, the "SumatraPDF" that displays a PDF just shrinks the PDF each time I scan in a new barcode and doesn't play the sound. However, when I manually hit the "Enter" button I do get the alert. Any help would be greatly appreciated. #include <Misc.au3> ;needed to use the _IsPressed function While 1 If WinActive("SumatraPDF") AND _IsPressed("0d") Then SoundPlay("error.wav") EndIf WEnd Edited October 9, 2019 by Yodavish
Developers Jos Posted October 9, 2019 Developers Posted October 9, 2019 (edited) Not that new as this is the second time this happened with your second start of a topic. Please look and read first before posting another topic! Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team Edited October 9, 2019 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Yodavish Posted October 9, 2019 Author Posted October 9, 2019 Hello AutoIt, I'm new to Autoit and I'm trying to play an alert sound when a 1D barcode is scanned while a certain window is still active. A typical barcode scan would be something like this: "AA19-1234" followed by a carriage return/enter. My original thought was to have it within a loop, and check if the "SumatraPDF" is active and if an "Enter" is sent when a barcode is accidentally scanned. But it doesn't work when I scan a barcode, the "SumatraPDF" window that displays a PDF just shrinks the PDF each time I scan in a new barcode and doesn't play the sound. However, when I manually hit the "Enter" button I do get the alert. Any help would be greatly appreciated. I've even tried using the hex value for the first character of the scanned barcode "A" or hex value "41", but that doesn't work either when I scan the barcode. I'm assuming the barcode scan isn't detected at all by AutoIt? My code is below: #include <Misc.au3> ;needed to use the _IsPressed function Local $hDLL = DllOpen("user32.dll") While 1 If WinActive("SumatraPDF") AND _IsPressed("0d",$hDLL) Then SoundPlay("error.wav") EndIf WEnd
Developers Jos Posted October 9, 2019 Developers Posted October 9, 2019 @Yodavish, Why did you yet create another topic? *merged* Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Yodavish Posted October 9, 2019 Author Posted October 9, 2019 @Jos I saw two different forums, (use the AutoIt General Help and Support or AutoIt Technical Discussion forums) so I wanted to see if someone could help answer this question that's all.
Developers Jos Posted October 9, 2019 Developers Posted October 9, 2019 9 minutes ago, Yodavish said: I saw two different forums, (use the AutoIt General Help and Support or AutoIt Technical Discussion forums) so I wanted to see if someone could help answer this question that's all. Forumrules 1 of any forum out there is not to crosspost the same question in multiple places as that is pretty impolite toward the community and shows you are impatient. So what is the urgency on this you can't wait for somebody to stop by and willing to offer the spare time to you? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Yodavish Posted October 9, 2019 Author Posted October 9, 2019 @Jos My apologies, I've been working on this project from some time and it has me frustrated that I can solve it.
TheXman Posted October 9, 2019 Posted October 9, 2019 4 hours ago, Yodavish said: However, when I manually hit the "Enter" button I do get the alert. It appears that you answered your own question as to why _IsPressed() is not working. _IsPressed() is looking for keyboard keys being pressed. Obviously the barcode scanner is not using the keyboard to enter data. Most likely, its driver is just sending characters directly to whatever has focus. So using _IsPressed() will not be able to capture non-keyboard related events/characters. You will need to find a different method of capturing scanner output or application input. Unfortunately, I can't help you figure out a better solution because there's not enough information to work with, I don't use SumatraPDF, and I don't currently have a barcode scanner to test with. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Yodavish Posted October 9, 2019 Author Posted October 9, 2019 @TheXman Well, I tried using HotKeySet and scanned in the barcode and the message did alert. So the scan with "Enter" is correct. However, I can't get it to actually send the enter key when the viewer is not active. SumatraPDF is just pdf viewer. HotKeySet("{ENTER}", checkBrowser) Func checkBrowser() Msgbox(0,"Debug", "Enter is detected") If WinActive("SumatraPDF") Then SoundPlay("error.wav") Else Send("{ENTER}") EndIf EndFunc
TheXman Posted October 9, 2019 Posted October 9, 2019 (edited) Yes, I'm quite familiar with SumatraPDF. I just said that I don't have it and that's because I don't use it. Maybe I just don't understand what exactly you are trying to accomplish. Can you explain, in different words, what it is you want to do? Is it that you are trying to be able to tell when a barcode scan has completed? What does SumatraPDF have to do with the task you're trying to accomplish? I'm a bit confused. Edited October 9, 2019 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Yodavish Posted October 9, 2019 Author Posted October 9, 2019 @TheXman I have GUI with an input that the user can scan in a 1D barcode. The barcode is pushed to 2 separate applications, one opens the PDF in the SumatraPDF and the other in a 3rd party application where the user can perform some recording task. The user typically will not look at the screen when they are scanning (pretty standard until they start their recording task), so they want me to check if the SumatraPDF viewer is active if they accidentally scan in a barcode, if so, have it play an alert sound to alert them that they are still on the current scanned in barcode. I hope that cleared up things.
TheXman Posted October 9, 2019 Posted October 9, 2019 Yes, that definitely sheds a little more light on the issue. Unfortunately, I still don't understand enough about your process and its steps to be of any help. Sorry, but I still can't visualize the issue and all of its steps. Hopefully someone else may be able to. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Yodavish Posted October 9, 2019 Author Posted October 9, 2019 Ok, I got it to work! While 1 HotKeySet("{ENTER}", checkBrowser) ... ;additional code WEnd Func checkBrowser() ; Check is SumatraPDF is active If WinActive("SumatraPDF") Then SoundPlay("error.wav") Else ; Disables the HotKeySet func for the remaining of this one loop HotKeySet("{ENTER}") Send("{ENTER}") EndIf EndFunc
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