Results 1 to 7 of 7
- 03-30-2012, 12:43 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 6
- Rep Power
- 0
Key Binding (hotkey) for Sending Audio, how do I?
Hey there all!
I have a Java app that sends audio to a server. As of now, a person has to click and hold the button while they speak through their microphone. I would like to add a hotkey so that they only have to press the specified key to record their voice. Also, I would like to be able to use the down key as a possible hotkey (yes I know it's weird, but I do have my reasons). After reading around I've found that Key Binding is probably the best way to go, but I'm unsure of how to go about this. The code is as follows:
How would I attach a random hotkey such as "F3" to the button input? Also, would Key Binding be the best way, or is there another simpler way?Java Code:setTitle("RecordAudio"); JButton button=new JButton("Push this Button to Speak"); button.addMouseListener(this); add(button); setSize(new Dimension(300,100)); setDefaultCloseOperation(EXIT_ON_CLOSE); } line.open(format); line.start(); int count = line.read(buffer, 0, buffer.length); if (count > 0) { output.writeInt(reverse(count)); output.write(buffer, 0, count); } } output.writeInt(0); output.close(); line.close(); } catch (LineUnavailableException e) { say("Line unavailable: " + e); } catch (IOException e) { say("I/O problems: " + e); } } public void stopRunning() { running=false; } @Override public void mouseClicked(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { Thread thread=new Thread(this); thread.start(); } @Override public void mouseReleased(MouseEvent e) { stopRunning(); } public static void main(String [] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); return; } MicrophoneInput mic=null; try { mic = new MicrophoneInput(); mic.setVisible(true); } catch (LineUnavailableException e) { say("Line unavailable: "+e); } }
Thanks in advance for any and all help.
- 03-30-2012, 01:45 AM #2
Re: Key Binding (hotkey) for Sending Audio, how do I?
Why do they have to hold the key down? Why not toggle the state: First press ON second press OFF.
If you don't understand my response, don't ignore it, ask a question.
- 03-30-2012, 02:30 AM #3
Member
- Join Date
- Jan 2012
- Posts
- 6
- Rep Power
- 0
Re: Key Binding (hotkey) for Sending Audio, how do I?
I'm assuming you're talking about the JButton instead of the hotkey, so the answer is because of how the server end translates the audio. If they have a start/stop button the user can very likely leave it recording on accident which would definitely mess with the server end of things.
So the original question remains, what do I need to do to bind a hotkey to the button?
- 03-30-2012, 02:34 AM #4
Re: Key Binding (hotkey) for Sending Audio, how do I?
Not sure how a "hot" key will change the leaving it on problem. You will get the same one event in the program when the key is pressed. The user will be required to tell the system when to turn off.
If you don't understand my response, don't ignore it, ask a question.
- 03-30-2012, 02:43 AM #5
Member
- Join Date
- Jan 2012
- Posts
- 6
- Rep Power
- 0
Re: Key Binding (hotkey) for Sending Audio, how do I?
Well, I figured that there would be some sort of way to attach a hotkey to simulate what the mouse button does (i.e. mouse press on button, record, release mouse button, stop recording). I thought there was a way to do the same exact thing except by pressing/releasing a predefined keyboard key.
- 03-30-2012, 02:50 AM #6
Re: Key Binding (hotkey) for Sending Audio, how do I?
I don't know what you mean by a "hot" key and how it is related to a mouse event.
How could that be used to turn off the recording? Wouldn't the user still have to remember to do something?
This took a while to find:
http://docs.oracle.com/javase/tutori...eybinding.htmlLast edited by Norm; 03-30-2012 at 02:55 AM.
If you don't understand my response, don't ignore it, ask a question.
-
Re: Key Binding (hotkey) for Sending Audio, how do I?
Key Bindings could very well work for you, but you'll have to take care to do all audio code in a background thread. You would create an Action for activating the audio that is triggered by keypress and another Action to stop audio recording that is triggered by key release, and again while the Action code's actionPerformed must be on the EDT or event thread, the audio driver code must then be called in a background thread.
Similar Threads
-
How to add hotkey (F12) to a button?
By steven.smith in forum AWT / SwingReplies: 7Last Post: 01-21-2012, 04:49 AM -
sending JMS messages to different queues than the one sending from
By Dark-Redd in forum Advanced JavaReplies: 0Last Post: 11-07-2011, 09:48 AM -
Help: Key Binding
By mine0926 in forum New To JavaReplies: 0Last Post: 08-06-2010, 04:52 AM -
outside hotkey
By Dennis in forum Advanced JavaReplies: 4Last Post: 06-18-2010, 07:37 PM -
How to add hotkey(Ctrl+VK) to a button?
By rpwtdj in forum Advanced JavaReplies: 5Last Post: 01-10-2008, 02:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks