ctrl + c keyboard event not working in as2.0 - actionscript-2

I'm using Macromedia Flex 1.5 with AS 2.0, I want to keep ctrl + c keyboard event for a datagrid, I'm trying following code, but it's not working. What am I doing wrong?
<mx:Script>
<![CDATA[
function myOnKeyDown() {
if (Key.isDown (Key.CONTROL) && Key.isDown(67))
{ mx.controls.Alert.show("Copied Succesfully: ");
}
else
{
mx.controls.Alert.show("Press control + c to copy: ");
}
}
]]>
</mx:Script>
<mx:DataGrid width="100%" height="35%" id="cur1_DataGrid" sortableColumns="false" change="level1var.checkForChanges()" keyDown="myOnKeyDown()">

I'm tracking the state of the CTRL key and I'm okay with the results except when it comes to key combinations.
Press the CTRL key and you'll see it traces "CTRL on". Release it and you'll see it traces "CTRL off". No problem there. Now press CTRL and then press the C key (as in copy), now release C, then release the CTRL key and you see nothing traces.
i.e, if(Key.isDown(67)) is returning true................... (or)
if(Key.isDown(Key.CONTROL)) is returning true.........
but (Key.isDown(Key.CONTROL) and Key.isDown(67)) is not returning......

Related

Handle VueJS event only when key is pressed

I use VueJS component provided by 3rd-party library, which has its own events. I can handle such events as usual with "v-on" directive and specifying interesting event name, like that:
<TheComponent v-on:itemchanged="handler"/>
But is it possible to run handler only when 'itemchanged' occurs with CTRL key pressed? The handler should not run when CTRL key is not pressed.
I tried to play with click.crtl and keydown.ctrl but have no success.
Is it possible to run handler only when 'itemchanged' occurs with CTRL key pressed?
Assuming itemchanged is triggered by a change event: no, not without a workaround. Unlike keyboard and mouse events, change contains no keyboard info. You'll need to track the status of ctrl keypresses independently because JavaScript has no way of testing whether a key is down outside of those events.
Plugin
One encapsulated way to accomplish it is with a plugin:
const pluginKeypresses = function(Vue) {
const keyPresses = {
Control: false
}
window.onkeyup = function(e) { keyPresses[e.key] = false; }
window.onkeydown = function(e) { keyPresses[e.key] = true; }
Vue.prototype.$keyPresses = Vue.observable(keyPresses);
}
Vue.use(pluginKeypresses);
Note: The e.key detection here is the current standard as of 11/2020, but is not yet fully supported by IE and some other browsers. If IE matters to you, change the key detection implementation to your liking.
Usage
From anywhere in the app you can test this.$keyPresses.Control (boolean)
Demo
Don't you receive an event object with this event ? By adding a parameter to handler you should be able to catch the event, and check inside which key is pressed. Then just add a if statement at the beginning of you handler function.

Vue.js / Vuex click function is not working for cmd + click

I want to fire a function for cmd + click. But it looks impossible at least for my keyboard.
My keyboard type:
Macbook Turkish Q
It seems like because of Macbook CMD key works depend on browser, How can I set new key codes for vue.js easily?
<div #click="foo($event)" ></div>
foo(e){
console.log(e.ctrlKey) // If I press CMD and Click to DIV result always FALSE
console.log(e.shiftKey) // If I press SHIFT and Click to DIV result TRUE (shift working but cmd is not working)
}
If you check e.metaKey it works! it handles CMD now.
Thank you.

How to press shift + ctrl + s in Selenium

How to press shift + ctrl + s in Selenium ?
I have used the code below:
Actions action = new Actions(driver);
action.sendKeys(Keys.chord(Keys.SHIFT + Keys.CONTROL + "s")).perform();
its Throwing error
If you simply send a series of keys, then Webdriver for each keycode first press a given key, then depress it.
So your code sendKeys(Keys.chord(Keys.SHIFT + Keys.CONTROL + "s") is equivalent to the below series of events in the time:
Press SHIFT
Depress SHIFT
Press CONTROL
Depress CONTROL
Press s
Depress s
This is not what you want, because you are excpecting that Ctrl and Shift have been pressed and are held at the moment of time when the S key is pressed.
You need to use Actions#keyDown method to press the key and leave it in the pressed state, and later Actions#keyUp to release the key. So the sequence of actions might be:
Press SHIFT - using keyDown
Press Ctrl - using keyDown
Press then release S (this key can be pressed and immediately released using sendKeys method)
Wait for an visible effect of pressing Ctrl-Shift-S
Release Ctrl - using keyUp
Release Shift - using keyUp
Points 5 and 6 (releasing keys) must be done in order to avoid unexpected effects later in the test code (don't leave Ctrl+Shift in a pressed state).
Here is a link to simple page on jsfiddle which help us to test our WebDriver code.
<body>
<p>Press a key on the keyboard in the input field to find out if the Ctrl-SHIFT key was pressed or not.</p>
<input id="ctrl_shift_s" type="text" onkeydown="isKeyPressed(event)">
<p id="demo"></p>
<script>
function isKeyPressed(event) {
console.log( event.keyCode);
var x = document.getElementById("demo");
if (event.shiftKey && event.ctrlKey && event.keyCode == 83 ) {
x.innerHTML = "The Ctrl-SHIFT-S keys were pressed!";
} else {
x.innerHTML = "Please press Ctrl-SHIFT-S";
}
}
</script>
</body>
If you move a cursor to INPUT field on this page (id="ctrl_shift_s" of this element), and then press Ctrl-SHIFT-S keys (holding SHIFT and Ctrl), then a message will appear The Ctrl-SHIFT-S keys were pressed!
Below is an example (working) code tested agaist the above test page using latest IE,Firefox and Chrome drivers. You must use requireWindowFocus(); option in order to run Actions in IE driver.
WebDriver driver= null;
try{
System.setProperty("webdriver.ie.driver", "C:\\instalki\\IEDriverServer.exe");
System.setProperty("webdriver.chrome.driver", "C:\\instalki\\chromedriver.exe");
System.setProperty("webdriver.gecko.driver", "C:\\instalki\\geckodriver.exe");
InternetExplorerOptions opt = new InternetExplorerOptions();
opt.requireWindowFocus();
// driver=new InternetExplorerDriver(opt);
// driver = new ChromeDriver();
driver = new FirefoxDriver();
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait( driver, 10);
driver.get("https://jsfiddle.net/39850x27/2/");
final By inputField = By.id("ctrl_shift_s");
final By messageWeWaitFor = By.xpath("//*[text() = 'The Ctrl-SHIFT-S keys were pressed!' ]");
final By frame = By.name("result");
// Swift to a frame (our test page is within this frame)
driver.switchTo().frame(driver.findElement(frame));
// move a corsor to the field
wait.until(ExpectedConditions.elementToBeClickable(inputField)).click();
Actions a = new Actions(driver);
// Press SHIFT-CTRL-S
a.keyDown(Keys.SHIFT)
.keyDown(Keys.CONTROL)
.sendKeys("s")
.build()
.perform();
//Wait for a message
wait.until(ExpectedConditions.visibilityOfElementLocated(messageWeWaitFor));
System.err.println("Success - Ctrl-Shift-S were pressed !!!");
// Sleep some time (to see the message is really on the page)
Thread.sleep(5000);
// Release SHIFT+CTRL keys
a.keyUp(Keys.CONTROL)
.keyUp(Keys.SHIFT)
.build()
.perform();
}finally {
if(driver!=null) {
driver.quit();
}
}

Using auto hotkey to swap Ctrl & Alt and implement Ctrl Tab

While using AutoHotKey I wanted to setup a rule to swap the left alt and left ctrl. I can do this by doing:
LAlt::LCtrl
LCtrl::LAlt
I then wanted to keep the 'alt tab' functionality bound do those physical keys, thus I tried
LCtrl & Tab::AltTab
In addition to the two uptop, yet it won't work. If I put it like so:
LCtrl & Tab::AltTab
LAlt::LCtrl
LCtrl::LAlt
Then the tab will work, however the ctrl alt swap will be broke. Any suggestions?
The hotkey documentation talks about wildcards
Wildcard: Fire the hotkey even if extra modifiers are being held down. This is often used in conjunction with remapping keys or buttons. For example:
*#c::Run Calc.exe ; Win+C, Shift+Win+C, Ctrl+Win+C, etc. will all trigger this hotkey.
*ScrollLock::Run Notepad ; Pressing Scrolllock will trigger this hotkey even when modifer key(s) are down.
So try this
*tab::
{ if(GetKeyState("LAlt", "P"))
{ Send {LControl up}{Alt down}{tab}
KeyWait, tab
}else
{ send {tab}
}
return
}
~LAlt Up::
{ send {lalt up}
return
}
LAlt::LCtrl
LCtrl::LAlt
I improved this slightly to fix shift tab not working, now you can use Shift+tab as expected where as before you couldn't (was frustrating trying to fix indentation(outdent) when coding) I may improve this more and get Shift+Alt+Tab working
*tab::
{
if(GetKeyState("LAlt", "P")){
Send {LControl up}{Alt down}{tab}
KeyWait, tab
} else if(GetKeyState("LShift", "P")){
Send {LShift down}{tab}
KeyWait, tab
}else
{ send {tab}
}
return
}
~LAlt Up::
{ send {lalt up}
return
}
LAlt::LCtrl
LCtrl::LAlt
Just ran into the same problem myself, was looking for a more straightforward solution. If you swap Alt and Ctrl using SharpKeys (or other registry remapping tool) from there it's a simple:
RCtrl & Tab::AltTab

Safari ignoring tabindex

I have 2 buttons next to a textbox and another textbox after the 2 buttons. The tabindex for the first textbox is 1000, the first button is 1001 and the second button is 1002. The second textbox has a tabindex of 1003.
When I press tab, the tabindex works fine in all browsers except for Safari, where it immediately moves from the first textbox to the second textbox although the tabindex has been set properly. Any ideas on how to prevent this issue?
By default tab-access is disabled in safari(!). To enable it, check "Preferences > Advanced > Press tab to highlight each item on a page".
Solution for iOS will be holding Option Key + Tab key.
Making Safari and a Mac accessible:
Testing on a Mac:
System Preferences -> Keyboard -> ShortCuts (tab) -> Full Keyboard Access -> All Controls
For Tabbing to work on Safari:
Preferences -> Advanced -> Press tab to highlight each item on a page (check this)
If you're writing your own webpage, I'd fix write something with a bit of jquery/javascript. This is what I've used on mine.
The drawback is that you prevent the default tab-key behavior on the page, which may be a bigger problem for accessibility in some situations. But I doubt it.
var Tab = {};
Tab.i = 1,
Tab.items = 0;
function fixTabulation () {
/* This can be used to auto-assign tab-indexes, or
# commented out if it manual tab-indexes have
# already been assigned.
*/
$('input, select, textarea').each(function(){
$(this).attr('tabindex', Tab.i);
Tab.i++;
Tab.items++;
});
Tab.i = 0;
/* We need to listen for any forward or backward Tab
# key event tell the page where to focus next.
*/
$(document).on({
'keydown' : function(e) {
if (navigator.appVersion.match("Safari")) {
if (e.keyCode == 9 && !e.shiftKey) { //Tab key pressed
e.preventDefault();
Tab.i != Tab.items ? Tab.i++ : Tab.i = 1;
$('input[tabindex="' + Tab.i + '"], select[tabindex="' + Tab.i + '"], textarea[tabindex="' + Tab.i + '"]').not('input[type="hidden"]').focus();
}
if (e.shiftKey && e.keyCode == 9) { //Tab key pressed
e.preventDefault();
Tab.i != 1 ? Tab.i-- : Tab.i = Tab.items;
$('input[tabindex="' + Tab.i + '"], select[tabindex="' + Tab.i + '"], textarea[tabindex="' + Tab.i + '"]').not('input[type="hidden"]').focus();
}
}
}
});
/* We need to update Tab.i if someone clicks into
# a different part of the form. This allows us
# to keep tabbing from the newly clicked input
*/
$('input[tabindex], select[tabindex], textarea[tabindex]').not('input[type="hidden"]').focus(function(e) {
Tab.i = $(this).attr('tabindex');
console.log(Tab.i);
});
}
$(document).ready(function() {
fixTabulation();
});
This is no perfect solution, but it's quite better than telling all your users to go change their Safari settings in System Prefs, lol.
I tried the following with Safari 5.1.5. I don't know how it works with older versions:
When "highlighting each item on a page" (see answer by graphicdivine) is disabled, you can use that function by pressing Option(alt) + tab.
If you don't (and the option is disabled), Safari will by default tab through all form-fields (like input, textarea, select...). For this fields, it will also accept/regard a tabindex. It will first tab through all form elements with a tabindex (in the order of the given indices) and then through the rest of the form elements in the order of their definition in HTML.
So if you define a tabindex="1" (or 1001) and "3" (or 1003) for two input-elements Safari will first focus this fields and then the others.
For those like me also looking how to enable this in browserstack: simply click the word "Safari" in the top left button of the screen, then you can select Preferences > Advanced > Press tab (as mentioned in https://stackoverflow.com/a/1914496/11339541)
Encountered the same issue and had to implement tab navigation programatically. Luckily found this jquery tabbable plugin https://github.com/marklagendijk/jQuery.tabbable and put it to good use, here's
require('../../node_modules/jquery.tabbable/jquery.tabbable');
$(document).ready(() => {
$(document).keydown((event) => {
if (event.keyCode === 9) {
window.$.tabNext();
event.preventDefault();
}
});
});