|
|
|
It is currently Tue May 21, 2013 3:54 pm
|
View unanswered posts | View active topics | View unsolved topics
|
Page 1 of 1
|
[ 8 posts ] |
|
Tying button to key stroke
| Author |
Message |
|
Micky.Franks
Trooper
Joined: Fri Aug 12, 2011 7:09 am Posts: 16
|
 Tying button to key stroke
How can I tie a button to a key? What I want is when I press the left keypad I want a bit to stay on while it's pressed and when released set to back to 0. I tried doing it with keystroke client scripts but it's not real reliable.
|
| Wed Aug 08, 2012 4:03 pm |
|
 |
|
Carl.Gould
Moderator
Joined: Sun Apr 02, 2006 2:46 pm Posts: 3793 Location: Sacramento, CA
|
 Re: Tying button to key stroke
This is going to be tricky. The trouble is that no matter where you put your script, it'll only work if no other component consumes that key stroke first.
I think the best way would be to put the script on a component that takes input focus and write a keystroke script on that component. And then train the operators to focus that component before trying to use the arrow key mechanism.
From a technical standpoint, there is a way to register a much higher level listener in Swing called an AWT event listener. This would be able to see the arrow keystroke no matter what the input selection was. Doing this is a bit, shall we say, "custom", and will be a bit tricky to get right. (It's not really a feature of Ignition, but a feature of the underlying Java Swing system)
_________________ Carl Gould
Software Development
Inductive Automation
|
| Wed Aug 08, 2012 4:18 pm |
|
 |
|
Micky.Franks
Trooper
Joined: Fri Aug 12, 2011 7:09 am Posts: 16
|
 Re: Tying button to key stroke
It's more for a toy I'm building. I'm trying to put together spare parts I have and build a remote operated vehicle with a camera on the front and have all the controls in Ignition. I can do it with a joystick but then that's another interface I would have to build and carry. I was trying to make it just two pieces, my laptop and the bot. I have an Ethernet radio and an ADAM Ethernet I/O module I was gonna use for the control of the vehicle.
|
| Wed Aug 08, 2012 5:21 pm |
|
 |
|
Carl.Gould
Moderator
Joined: Sun Apr 02, 2006 2:46 pm Posts: 3793 Location: Sacramento, CA
|
 Re: Tying button to key stroke
Alright, try this. Also, don't call into support asking questions about this script for your toy please or I'll get in trouble  As should be obvious, you'll want to insert your own code where the print statements are. Code: from java.awt import Toolkit from java.awt import AWTEvent from java.awt.event import AWTEventListener
class KeyListener(AWTEventListener): def eventDispatched(self, event): from java.awt.event import KeyEvent if event.getID() == KeyEvent.KEY_PRESSED: self.keyDown(event.getKeyCode()) elif event.getID() == KeyEvent.KEY_RELEASED: self.keyUp(event.getKeyCode()) def keyDown(self, code): from java.awt.event import KeyEvent if code == KeyEvent.VK_LEFT: print 'LEFT DOWN' elif code == KeyEvent.VK_RIGHT: print 'RIGHT DOWN' def keyUp(self, code): from java.awt.event import KeyEvent if code == KeyEvent.VK_LEFT: print 'LEFT UP' elif code == KeyEvent.VK_RIGHT: print 'RIGHT UP' Toolkit.getDefaultToolkit().addAWTEventListener(KeyListener(), AWTEvent.KEY_EVENT_MASK)
_________________ Carl Gould
Software Development
Inductive Automation
|
| Thu Aug 09, 2012 7:52 am |
|
 |
|
Micky.Franks
Trooper
Joined: Fri Aug 12, 2011 7:09 am Posts: 16
|
 Re: Tying button to key stroke
Carl.Gould wrote: Alright, try this. Also, don't call into support asking questions about this script for your toy please or I'll get in trouble   no problem
|
| Thu Aug 09, 2012 12:14 pm |
|
 |
|
Carl.Gould
Moderator
Joined: Sun Apr 02, 2006 2:46 pm Posts: 3793 Location: Sacramento, CA
|
 Re: Tying button to key stroke
I forgot to mention: this script should be in your project's client startup script.
_________________ Carl Gould
Software Development
Inductive Automation
|
| Thu Aug 09, 2012 1:02 pm |
|
 |
|
Micky.Franks
Trooper
Joined: Fri Aug 12, 2011 7:09 am Posts: 16
|
 Re: Tying button to key stroke
Would this be a script that runs at startup or does it have to run all the time?
|
| Thu Aug 09, 2012 3:51 pm |
|
 |
|
Carl.Gould
Moderator
Joined: Sun Apr 02, 2006 2:46 pm Posts: 3793 Location: Sacramento, CA
|
 Re: Tying button to key stroke
Client startup script.
_________________ Carl Gould
Software Development
Inductive Automation
|
| Thu Aug 09, 2012 6:04 pm |
|
 |
|
|
Page 1 of 1
|
[ 8 posts ] |
|
Who is online |
Users browsing this forum: Carl.Gould, Google [Bot] and 1 guest |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|