Matlab Java Robot Function Keys Mac OSX
3 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I'm using the Java Robot to try and control various actions similar to user inputs. Running on Mac (OSX, HighSierra), I'm unable to access the function keys using this method. In particular, the F3 key is also shared with the mission control, allowing users to see open apps in present screen. However, using various combinations of simulated key-presses, I've been unable to access this operation. I've got my keyboard set to initially ignore the 'functions' and F1/2 operate brightness... F10 mutes, etc. Wondering if I can use the robot to do the same. I'm using the functions similar to those on java robot site, posted by Sid Hazra on 1st Feb 2015. Sample function:
function Key_Stroke(s,Delay)
if nargin == 1
Delay = 0;
end
% This version uses the VK_xyz and eval approach.
import java.awt.Robot;
import java.awt.event.*;
kb = Robot;
eval(['kb.keyPress(KeyEvent.VK_' s '); kb.keyRelease(KeyEvent.VK_' s ');']);
pause(Delay);
This function contains both the press & release, so I've also got functions that do these events individually (simulating holding and releasing buttons on the keyboard). Running these with the following type of thing is how I use the robot:
Key_HOLD('CONTROL',0.1);
Key_Stroke('F3',0.1);
Key_RELEASE('CONTROL',0.1);
As mentioned, I've been unable to access the mission control using this method of trying the function keys and wonder if anyone can help (META press, ALT press, tried with the above, without success). To make things more interesting, macs have the option to enable the function key to operate the function buttons, so one must press the "fn" button on keyboard to get mission-control up (fn+F3). Running this still doesn't work (manually holding fn and letting Matlab "press" F3 with the java-robot).
I've also used getkey.m from the file exchange and pressing the function keys doesn't return anything when the Fn buttons are set to special features (mission control, volume, etc; not even empty array), and empty array is returned if they're operated as "F" keys, so I can't even see what number of key is being pressed and try replicating a button press by the things that way either, seeming like the "VK_F#" input to the KeyEvent may be for Windows rather than OS-X?
Also looked at "inputemu.m" from the file exchange but unsure if it would solve my problem either, so posting here hoping that someone with more experience can help quicker!
1 件のコメント
Samuel Arnold McKenzie
2023 年 9 月 22 日
this solution worked for me.
Then I used matlab to call python
https://www.mathworks.com/help/matlab/ref/pyrun.html
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!