keyboard-events

How to simulate Caps Lock keystroke with CGEventCreateKeyboardEvent in OS X

核能气质少年 提交于 2019-12-04 14:31:20
Has anyone had any luck simulating Caps Lock keystroke with CGEventCreateKeyboardEvent on OS X? Basically I have tried alphabetic character and alphanumeric character okay but Caps Lock. Hopefully, I would like to simulate Caps Lock keystroke to trun on/off the LED. I don't know what problem is for my test code. Has anyone had experinces for this? #include <stdio.h> #include <ApplicationServices/ApplicationServices.h> main() { bool wasCapsLockDown = CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, 57); if (wasCapsLockDown) printf("On\n"); else printf("Off\n"); ProcessSerialNumber psn;

Getting key names for keyboard codes in Swift

僤鯓⒐⒋嵵緔 提交于 2019-12-04 12:26:06
问题 I know others have asked similar questions, but I haven’t seen a definitive answer, and I’m still stuck. I’m trying to write a Swift function that takes a hardware-generated keyboard scan code, such as from an NSEvent, and returns the alpha-caps-locked name of the key, for the particular key arrangement (Dvorak, Qwerty, etc.) currently in effect in the OS (which might be different from the arrangement in effect when the code was generated). It’s my understanding that the only way to do this

How to detect keyboard events on hardware keyboard on iPhone (iOS)

亡梦爱人 提交于 2019-12-04 12:21:18
I have an app with a login page that has three fields for three different random characters. When the user leaves the last field, the soft keyboard disappears and the user can touch a "login" button on screen. When there is a hardware keyboard (bluetooth or physical) attached, I'd like to be able to hit "enter" on it. However because the user is not in a field, I can't see how to detect this key being pressed. Would anyone have advice on which class handles key press events? Presumably there is a delegate that I can use to receive these but my searches through the SDK haven't found anything.

Detect Ctrl + C and Ctrl + V in an input from browsers

耗尽温柔 提交于 2019-12-04 09:02:54
I am using the direct following and I do not detect the copy and paste with the keys inside the input, would someone know how? Thank you! export class OnlyNumberDirective { // Allow decimal numbers. The \, is only allowed once to occur private regex: RegExp = new RegExp(/[0-9]+(\,[0-9]{0,1}){0,1}$/g); // Allow key codes for special events. Reflect : // Backspace, tab, end, home private specialKeys: Array<string> = [ 'Backspace', 'Tab', 'End', 'Home', 'Delete', 'Del', 'Ctrl', 'ArrowLeft', 'ArrowRight', 'Left', 'Right' ]; constructor(private el: ElementRef) { } @HostListener('keydown', [ '$event

Firing ctrl+r, ctrl+a, ctrl+q events on a button click

橙三吉。 提交于 2019-12-04 08:31:10
I need to fire the Ctrl + R , Ctrl + A , Ctrl + Q events when a user clicks on a button. I was working on the following code: $(document).ready(function () { $('#Button1').click(function () { var evt = $.Event("keypress"); evt.keyCode = 81; evt.ctrlKey = true; evt.shiftKey = true; $(document).trigger(evt); }); }); PurkkaKoodari You can't simulate browser control keys, but you can simulate their effects. Ctrl - R refreshes. function refresh() { location.reload(true); } Ctrl - A selects everything. Code is from here . function selectAll() { var e = document.getElementsByTagName('body')[0]; var r

Non-blocking keyboard read - C/C++

你。 提交于 2019-12-04 06:29:18
问题 I got this following function with me working now. But what I need to improve is that it would read input from the keyboard (on the terminal) EVEN THOUGH IT IS NOT BEING PRESSED. I need to know when it is NOT pressed (idle) so that the switch case block will fall into the default section. At this point, the read() function waits until there's an input from the user. Can anyone give a suggestion just based on modifying this following code? NOTE: I'm a Java programmer, and still learning C/C++

How to fire keyboard events in Javascript?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 05:37:31
问题 I'm giving a value to a textbox and then giving focus to it. document.getElementById('textbox').value="abcd"; document.getElementById('textbox').focus(); Then, I am creating a keyboard event and trying to fire the CTRL + A key combination (trying to select the text inside the textbox ) by writing the following code: var myEvent = document.createEvent('KeyboardEvent'); myEvent.initKeyEvent("keypress", true, true, window, true, false, false, false, 0, 97); document.getElementById('textbox')

Press multiple keys at once to get my character to move diagonally

让人想犯罪 __ 提交于 2019-12-04 05:32:52
The problem I'm having is that I'm trying to make my character move diagonally on screen when a user presses either the K_UP key and K_RIGHT key or the K_UP key and K_DOWN key, etc. Here is my code for character movement (event handling): 1. #Event Handling 2. for event in pygame.event.get(): 3. if event.type == pygame.QUIT: 4. sys.exit() 5. elif (event.type == KEYDOWN): 6. if ((event.key == K_ESCAPE) 7. or (event.key == K_q)): 8. sys.exit() 9. if (event.key == K_UP): 10. self.char_y = self.char_y - 10 11. if (event.key == K_DOWN): 12. self.char_y = self.char_y + 10 13. if (event.key == K

drop/rewrite/generate keyboard events under Linux

隐身守侯 提交于 2019-12-04 04:51:23
I would like to hook into, intercept, and generate keyboard (make/break) events under Linux before they get delivered to any application. More precisely, I want to detect patterns in the key event stream and be able to discard/insert events into the stream depending on the detected patterns. I've seen some related questions on SO, but: either they only deal with how to get at the key events (key loggers etc.), and not how to manipulate the propagation of them (they only listen, but don't intercept/generate). or they use passive/active grabs in X (read more on that below). A Small DSL I explain

simulating key press event using SendInput with C#

末鹿安然 提交于 2019-12-04 04:28:50
问题 Following the advice from this thread: distinguish between keyboard's Real and Virtual key presses I'm trying to create a program, that will send keyboard's key-press events using SendInput() method. However, the problem is that when I try to simulate a key press event - nothing happens whatsoever. So far that's my code: [DllImport("user32.dll")] static extern UInt32 SendInput(UInt32 nInputs, [MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] INPUT[] pInputs, Int32 cbSize); [StructLayout