Java TSM AdjustCapsLockLEDForKeyTransitionHandling
Posted
技术标签:
【中文标题】Java TSM AdjustCapsLockLEDForKeyTransitionHandling【英文标题】: 【发布时间】:2021-08-23 01:15:13 【问题描述】:我正在尝试从KeyEvent
捕获上、下、右、左键,当我按下某个键时收到以下消息:
2021-06-05 00:46:11.176 java[47646:1823153] TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED 禁止
这是我的代码:
Character.java
import java.awt.Image;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
public class Character
private int dx;
private int dy;
private int x;
private int y;
private String imageLocation;
private Image image;
private boolean moveable;
public Character(int x, int y, String imgLoc, boolean m)
this.x = x;
this.y = y;
imageLocation = imgLoc;
ImageIcon ii = new ImageIcon(this.getClass().getResource(imageLocation));
image = ii.getImage();
moveable = m;
public void move()
if(moveable)
x += dx;
y += dy;
public boolean moveable()
return moveable;
public int getX()
return x;
public int getY()
return y;
public Image getImage()
return image;
public void keyPresed(KeyEvent e)
int key = e.getKeyCode();
if(key == KeyEvent.VK_LEFT)
System.out.println("left key pressed");
dx = -1;
if(key == KeyEvent.VK_RIGHT)
dx = 1;
if(key == KeyEvent.VK_UP)
dy = -1;
if(key == KeyEvent.VK_DOWN)
dy = 1;
public void keyReleased(KeyEvent e)
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT)
dx = 0;
if (key == KeyEvent.VK_RIGHT)
dx = 0;
if (key == KeyEvent.VK_UP)
dy = 0;
if (key == KeyEvent.VK_DOWN)
dy = 0;
** 添加:**
休息室.java
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Lounge extends JPanel implements ActionListener
private Timer timer;
private Player player;
public Lounge()
//addKeyListener(new TAdapter());
setFocusable(true);
setBackground(Color.BLACK);
setDoubleBuffered(true);
player = new Player(1000, 40);
timer = new Timer(5, this);
timer.start();
public void paint(Graphics g)
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(player.getImage(), player.getX(), player.getY(), this);
Toolkit.getDefaultToolkit().sync();
g.dispose();
@Override
public void actionPerformed(ActionEvent e)
player.move();
repaint();
private class TAdapter extends KeyAdapter
public void keyReleased(KeyEvent e)
player.keyReleased(e);
public void keyPressed(KeyEvent e)
player.keyReleased(e);
Main.java
import javax.swing.JFrame;
public class Main extends JFrame
public Main()
add(new Lounge());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1280,720);
setLocationRelativeTo(null);
setTitle("Be My Guest");
setResizable(false);
setVisible(true);
public static void main(String[] args)
new Main();
我在 MacBook pro 2017 上使用 Visual Studio Code
请帮帮我!
【问题讨论】:
我没有看到任何与您提供的日志/输出一致的日志记录语句。 对不起!我没有上传其他课程。 【参考方案1】:我认为问题在于最初按下 Caps-Lock 键,我在 here 上发现了一个类似的问题
我发现的另一个问题是 keyPressed
方法拼写错误为 keyPresed
也可能导致一些问题
【讨论】:
以上是关于Java TSM AdjustCapsLockLEDForKeyTransitionHandling的主要内容,如果未能解决你的问题,请参考以下文章