Оцените пж мой код на java swing и c# я писал 10 часов от босса кфс до пик ми
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.*;
public class Main extends JFrame {
private boolean squareVisible = false;
private int width;
private int height;
public Main() {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension screenSize = tk.getScreenSize();
width = screenSize.width;
height = screenSize.height;
squareVisible = readSquareVisibleFromFile();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Rectangle usableBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
setBounds(usableBounds);
JPanel panelz = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.DARK_GRAY);
g.fillRect(0, height - 50, width, 50);
g.fillRect(0, 0, 50, 50);
if (squareVisible) {
g.setColor(Color.BLUE);
g.fillRect(5, height - 153, 100, 100);
}
//g.setColor(Color.RED);
//g.fillRect(150, height - 150, 100, 100);
}
};
add(panelz);
setUndecorated(true);
setAlwaysOnTop(true);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setVisible(true);
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ALT) {
squareVisible = !squareVisible;
writeSquareVisibleToFile(squareVisible);
repaint();
}
}
});
}
private boolean readSquareVisibleFromFile() {
File file = new File("C:\\SomeDir\\libplus\\altbind.txt");
if (!file.exists()) {
return false; // по умолчанию скрыт
}
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line = reader.readLine();
return line != null && line.trim().equalsIgnoreCase("T");
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
private void writeSquareVisibleToFile(boolean visible) {
File file = new File("C:\\SomeDir\\libplus\\altbind.txt");
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file, false))) {
writer.write(visible ? "T" : "F");
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(Main::new);
}
}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.IO;
class Program
{
private const int WH_KEYBOARD_LL = 13;
private const int WM_KEYDOWN = 0x0100;
private static LowLevelKeyboardProc _proc = HookCallback;
private static IntPtr _hookID = IntPtr.Zero;
static void Main()
{
_hookID = SetHook(_proc);
Console.WriteLine("Перехват клавиши Win активирован. Нажмите ESC для выхода.");
MSG msg;
while (GetMessage(out msg, IntPtr.Zero, 0, 0) != 0)
{
TranslateMessage(ref msg);
DispatchMessage(ref msg);
// Для выхода по ESC
if (msg.message == WM_KEYDOWN)
{
int vkCode = (int)msg.wParam;
if (vkCode == 0x1B) // ESC
break;
}
}
UnhookWindowsHookEx(_hookID);
}
private static IntPtr SetHook(LowLevelKeyboardProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
GetModuleHandle(curModule.ModuleName), 0);
}
}
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
{
int vkCode = Marshal.ReadInt32(lParam);
string filePath = "C:\\SomeDir\\libplus\\winbind.txt";
string filePatha = "C:\\SomeDir\\libplus\\altbind.txt";
string path = @"C:\SomeDir";
string subpath = @"libplus\";
DirectoryInfo dirInfo = new DirectoryInfo(path);
if (vkCode == 0x5B || vkCode == 0x5C)
{
Console.WriteLine("Win key pressed, blocked.");
if (!dirInfo.Exists)
{
dirInfo.Create();
}
dirInfo.CreateSubdirectory(subpath);
try
{
using (StreamWriter writer = File.CreateText(filePath))
using (StreamWriter writers = File.CreateText(filePatha))
{
writer.WriteLine("True :)");
writers.WriteLine("F");
}
}
catch (Exception ex) {
Console.WriteLine($"Ошибка: {ex.Message}");
}
return (IntPtr)1;
}
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
[StructLayout(LayoutKind.Sequential)]
public struct MSG
{
public IntPtr hwnd;
public uint message;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public POINT pt;
}
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
}
[DllImport("user32.dll")]
private static extern int GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
[DllImport("user32.dll")]
private static extern bool TranslateMessage([In] ref MSG lpMsg);
[DllImport("user32.dll")]
private static extern IntPtr DispatchMessage([In] ref MSG lpMsg);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
}
По дате
По Рейтингу
Люблю крылышки кфс