import os
import sys
import signal
import ctypes
import atexit
from ctypes import wintypes, windll, CFUNCTYPE, POINTER, c_int, c_void_p, byref
from collections import namedtuple
event_types = {
0x100: 'key down',
0x101: 'key up',
0x104: 'key down',
0x105: 'key up',
}
KeyEvent = namedtuple("KeyEvent", ['event_type', 'key_code', 'scan_code', 'alt_pressed', 'time'])
handlers = []
def listener():
def hook(nCode, wParam, lParam):
event = KeyEvent(event_types[wParam], lParam[0], lParam[1], lParam[2] == 32, lParam[3])
for handler in handlers:
handler(event)
return windll.user32.CallNextHookEx(hook_id, nCode, wParam, lParam)
CMPFUNC = CFUNCTYPE(c_int, c_int, c_int, POINTER(c_void_p))
pointer = CMPFUNC(hook)
windll.kernel32.GetModuleHandleW.restype = wintypes.HMODULE
windll.kernel32.GetModuleHandleW.argtypes = [wintypes.LPCWSTR]
hook_id = windll.user32.SetWindowsHookExA(0x00D, pointer, windll.kernel32.GetModuleHandleW(None), 0)
atexit.register(windll.user32.UnhookWindowsHookEx, hook_id)
while True:
msg = windll.user32.GetMessageW(None, 0, 0, 0)
windll.user32.TranslateMessage(byref(msg))
windll.user32.DispatchMessageW(byref(msg))
def run_on_enter(event):
if event.event_type == 'key up' and event.key_code == 120259084301:
os.system('notepad.exe')
if __name__ == '__main__':
signal.signal(signal.SIGINT, lambda s, f: sys.exit())
handlers.append(run_on_enter)
listener()
roots = Category.objects.filter(parent__isnull=True)
categories = category.get_descendants(include_self=False)
goods = Goods.objects.filter(category__parent__isnull=False)
BufferedReader stdInBReader = new BufferedReader(new InputStreamReader(System.in, "cp866"));
String encoding = System.getProperty("console.encoding", "utf-8");
BufferedReader stdInBReader = new BufferedReader(new InputStreamReader(System.in, encoding));
java -Dconsole.encoding=cp866 Ex
import java.io.Console;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
public class Ex {
private static final String encoding;
static {
String e = null;
try {
final Class<Console> clazz = Console.class;
final Method method = clazz.getDeclaredMethod("encoding", new Class[0]);
method.setAccessible(true);
e = (String) method.invoke(null);
}
catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException exc) {}
finally {
encoding = e;
}
}
public static void main(String[] args) throws IOException {
BufferedReader stdInBReader = new BufferedReader(new InputStreamReader(System.in, encoding));
}
}
if len([i for i in list if i is not None]) > 0:
...
if any(list):
...
if all(list):
...